Failure to Detect PDF Page Colors Using Aspose.PDF

We have tested the logic in this code example from the Aspose.PDF tutorial for detecting page color types, as applied to the attached document samples.
samples.zip (363.9 KB)

All pages are detected as type color when some are indeed type grayscale. Aspose.PDF versions 23.3.0 and 25.4.0 are both failing to properly detect grayscale pages in the attached PDF samples. Aspose.PDF version 18.1 appears to detect the color type appropriately albeit at performance of 15-20 seconds per page detection.

Thank you for your attention to this. We look forward to any replies.

@mbforte

It seems you are experiencing issues with the detection of page color types in your PDF documents using Aspose.PDF. Specifically, you mentioned that some pages are incorrectly identified as color when they should be recognized as grayscale.

To troubleshoot this issue, you can refer to the code example provided in the Aspose.PDF documentation for detecting page color types. The code iterates through each page of a PDF document and checks the color type using the ColorType property. Here’s a simplified version of the code:

using Aspose.Pdf;

public class DeterminePageColor
{
    public static void Run()
    {
        // Open the PDF document
        Document pdfDocument = new Document("input.pdf");
        
        // Iterate through all pages
        for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
        {
            // Get the color type of the page
            Aspose.Pdf.ColorType pageColorType = pdfDocument.Pages[pageCount].ColorType;
            switch (pageColorType)
            {
                case ColorType.BlackAndWhite:
                    Console.WriteLine("Page # -" + pageCount + " is Black and white.");
                    break;
                case ColorType.Grayscale:
                    Console.WriteLine("Page # -" + pageCount + " is Gray Scale.");
                    break;
                case ColorType.Rgb:
                    Console.WriteLine("Page # -" + pageCount + " is RGB.");
                    break;
                case ColorType.Undefined:
                    Console.WriteLine("Page # -" + pageCount + " Color is undefined.");
                    break;
            }
        }
    }
}

Make sure you are using the correct version of the Aspose.PDF library, as you noted that version 18.1 detects the color types correctly, albeit with slower performance. If the newer versions (23.3.0 and 25.4.0) are not functioning as expected, it may be worth reporting this issue to Aspose support for further investigation.

If you continue to face issues, consider checking the structure of the PDF files you are testing against, as certain PDF characteristics might affect how color types are detected.

For more details, you can refer to the original code example in the Aspose documentation here.

If you have any further questions or need additional assistance, feel free to ask!

We are a licensed user of Apose.PDF seeking a response for this issue. The example code referred to by the bot shows the same issue with the detection of page color types in the sample PDF documents included in the attachment we provided. Is there a status for this?

@mbforte

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-59979

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.