PDF ColorType always Grayscale or Color

I’m attempting to determine the color type for each page of a PDF document using the following code (using Aspose.Pdf version 11.7):


using (var pdfDocument = new Aspose.Pdf.Document(Filename))
{
int numGrayscalePages = 0, numColorPages = 0, numBlackAndWhitePages=0;

for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
Aspose.Pdf.ColorType pageColorType = pdfDocument.Pages[pageCount].ColorType;

switch (pageColorType)
{
case Aspose.Pdf.ColorType.BlackAndWhite:
numBlackAndWhitePages++;
break;
case Aspose.Pdf.ColorType.Grayscale:
numGrayscalePages++;
break;
case Aspose.Pdf.ColorType.Rgb:
numColorPages++;
break;
case Aspose.Pdf.ColorType.Undefined:
LogWarning(“Document contains a page with unknown color type”);
break;
}
}
}

I can detect color pages and grayscale pages, but unfortunately, I can’t detect any pages as black and white. I’ve tried testing 50+ pdf’s scanned from multiple scanners that were set to B&W mode, converting known B&W (bitonal) Tiff files to pdf (using Aspose and ImageMagick), and creating a bitonal image in GIMP and exporting it as pdf. All pdfs have been detected as grayscale. I have no way of externally testing if these files are actually B&W and Aspose.Pdf is detecting them wrong, or if they are all encoded using grayscale, despite using every setting to make them bitonal.

I’ve attached a selection of documents I’ve created. Unfortunately, the rest that I tested with were client documents.

Can you shed some light on this for me?

Cheers,

Peter

Hi Peter,


Thanks for contacting support.

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial; -webkit-text-stroke: #000000} span.s1 {font-kerning: none}

I have tested the scenario and have managed to reproduce the problem that PDF ColorType is returning GrayScale or Color for your provided documents. For the sake of correction, I have logged it as PDFNET-42335 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time.


We are sorry for this inconvenience.


Best Regards,

Thanks for the quick reply Fahad. I’ll let our client know that you’re looking into it.


Cheers,

Peter

Hi Peter,


As soon as we have some definite updates, we will let you know.

The issues you have found earlier (filed as PDFNET-42335) have been fixed in Aspose.PDF for .NET 21.5.