Issue with Aspose.PDF for .NET - TIFF Conversion in AKS Linux Container

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

@ATS
Does this happen with all pdf documents or just some? If not with everyone, please attach the document with which this happens.

It happens with all documents , no specific scenario . Tiff generated is black and white always

By looking into other posts on the forum , i just replaced my Aspose.Pdf with Aspose.Pdf.Drawing.
and used the same code. and it worked.

Is this correct?

@ATS
Yes, this is the right approach - the Aspose.Pdf.Drawing library was specifically created to work in Linux. I planned to test the work with it myself and only then, if there were no errors, offer this option to you. It’s great that you saw and verified this for yourself.
In the future, it is planned to make Aspose.Pdf.Drawing the main and only option (renaming it Aspose.Pdf)

Thats great!, Thanks so much.

And one more thing, the code i provided above will work for all the approaches right.
is it better to read the PDF document directly or load it into stream and then to Document which i have in my code as above?

@ATS
They can be considered equivalent options.
As a general point, when you read everything into a stream from a file first, you end up with fewer disk accesses, which can improve performance. But the price for this will be the use of more memory (to load data into the stream).
I also draw attention to the desirability of use using for the Aspose.Pdf.OptimizedMemoryStream and Aspose.Pdf.Document objects

Thanks for the explanation, “Using” will be definitely used for better releasing of resources .

And on the use of more memory, as per the Aspose documentation its recommending to go with the stream option for large PDFs which are greater than 2.5 GB memory.

in my scenario, i have the read the PDF only once and convert it to Single Page TIFFs , and i may get large PDFs too, considering this what will be my better approach in this ?

@ATS
Accordingly, it is better to use the approach recommended for large documents, as you are doing.