I am using Aspose.PDF for .NET to convert PDF files to TIFF format. The conversion works fine on my Windows machine, but I’m encountering an issue when I deploy the same code in an AKS Linux container.
The issue is that the converted TIFF files are coming out in black and white instead of color. This only happens when the code is deployed in the AKS Linux container.
Here is the code I’m using for the conversion:
Aspose.Pdf.OptimizedMemoryStream ms = new Aspose.Pdf.OptimizedMemoryStream();
// Read large size PDF document from disk using FileStream
using (FileStream file = new FileStream(inputpath, FileMode.Open, FileAccess.Read))
{
byte[] bytes = new byte[file.Length];
file.Read(bytes, 0, (int)file.Length);
// Write large PDF bytes to OptimizedMemoryStream
ms.Write(bytes, 0, (int)file.Length);
}
//Load a pdf document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(ms);
// Create Resolution object
Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(300);
// Create TiffSettings object
Aspose.Pdf.Devices.TiffSettings tiffSettings = new Aspose.Pdf.Devices.TiffSettings
{
Compression = Aspose.Pdf.Devices.CompressionType.LZW,
Depth = Aspose.Pdf.Devices.ColorDepth.Default,
Shape = Aspose.Pdf.Devices.ShapeType.None,
};
// Create TIFF device
Aspose.Pdf.Devices.TiffDevice tiffDevice = new Aspose.Pdf.Devices.TiffDevice(resolution, tiffSettings);
for (int i = 0; i < pdfDocument.Pages.Count; i++)
{
// Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, i+1, i+1, outputpath + "_image" + (i+1) +".tiff");
}
I have tried changing the ColorDepth to Format24bpp, but the output is still black and white. I would appreciate any guidance on how to resolve this issue.
My docker file for reference
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 5000
EXPOSE 443
RUN sed -i’.bak’ ‘s/$/ contrib/’ /etc/apt/sources.list
RUN apt update && apt install -y
libgdiplus
libxkbcommon-x11-0
libc6
libc6-dev
libx11-dev
libgtk2.0-0
libnss3
libatk-bridge2.0-0
libx11-xcb1
libxcb-dri3-0
libdrm-common
libgbm1
libasound2
libxrender1
libfontconfig1
libxshmfence1
ttf-mscorefonts-installer
fontconfig
dirmngr
&& rm -rf /var/lib/apt/lists/*
RUN fc-cache -f -v
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
I am using Aspose.PDf latest version from Nuget