How do I detect blank (or colored) page in PDF?

Q: How do I detect blank (or colored) page in PDF?
A: One way to implement a function to check if a PDF page contains
color information is by inspecting all Elements on a page (e.g. using
ElementReader class as shown in ElementReaderAdv sample project - The main
problem with this approach is that it is fairly complex to implement
there are many cases, you need to implement visibility checking etc).

A much simple approach is to use PDFDraw class to obtain a page
(e.g. at 96dpi; pdfdraw.GetBitmap();
samplecode.html#PDFDraw). You can then traverse all pixels on the
page. If there is any pixel where RGB (red, green, and blue) color
components do not match you have a PDF page with some color
information, otherwise you can treat the page as grayscale.

You can use the same approach to detect if a PDF page is blank (i.e.
if all pixels are transparent or white).

Please keep in mind that there are some important differences between
the above approaches. For example, rasterizing the page will not tell
you whether page contains some colored elements which are not visible
(e.g. because they are obscured by other elements or are outside of
page boundaries). So in case you need to implement a preflight like
tool for PDF, the approach using ElementReader is the way to go.

Q: I use the following steps to detect PDF pages for color / blanks:

1. Obtain a Black&White (all pages) PDF file where color space is
2. Rasterize each page of the PDF file to RGB+Alpha output
3. analyze each RGB component of the rasterized output in memory

Result: colored components are detected (ex: R=8, G=9, B=9);
Expected: all BW components (R=255, G=255, B=255)
A: Color RGB(8, 9, 9) represents a fairly light grayscale. Since you
are rendering image using RGBA you may encounter some aliased colors
at the edges of polygons. I assume that alpha in this case is fairly
low (9?). You could either de-multiply the color with alpha (taking
into account small rounding issues +/-1), or disable anti-aliasing in
rasterizer (PDFDraw.SetAntiAliasing(false)).