3

With pdfinfo, I can easily count the number of pages in a PDF file, but that includes empty pages, e.g. before a chapter. What if I want the count of all non-empty packages – is there a tool for that?

  • 3
    Pages that seem to be empty when looked at by a human, may not be empty when looked at by a machine. Many PDF producers try to avoid adding empty pages: they make sure it doesn't happen by accident. When it is necessary to add an empty page, they usually add something to the empty page (could be anything; there's no standard way of doing this). That makes it very hard for software to detect empty pages. You'd need to render each page and then check if there are no visible elements. That costs a lot of CPU. – Bruno Lowagie Jun 24 '15 at 5:54
2

If by "empty page" you mean: when printed, it wouldn't cause any toner/ink marks on the page, you could use Ghostscript's new inkcov device which reports the ink coverage for each page. (It may be a bit slow to report final results; that is because it needs to virtually render each page in order to compute the ink coverage):

Example command:

$> gs -o -  -sDEVICE=inkcov sample2.pdf

Processing pages 1 through 8.
Page 1
 0.00000  0.00000  0.00000  0.02231 CMYK OK
Page 2
 0.02363  0.02363  0.02363  0.02363 CMYK OK
Page 3
 0.02527  0.02527  0.02527  0.00000 CMYK OK
Page 4
 0.03322  0.03322  0.03322  0.03322 CMYK OK
Page 5
 0.00000  0.00000  0.00000  0.03413 CMYK OK
Page 6
 0.00000  0.00000  0.00000  0.01984 CMYK OK
Page 7
 0.13274  0.13274  0.13274  0.03355 CMYK OK
Page 8
 0.00000  0.00000  0.00000  0.00000 CMYK OK

The values are integers in the range from 0..1, where a value of 1 represents a 100% ink coverage (for all pixels on the page). The above result hence means:

Page 8, when rendered, does not use any ink, hence it is "blank".

This does not mean that this page is really empty, when looked at in a PDF viewer. To list but only two examples:

  1. It could use white text on a white background, and this text could be highlighted and copy'n'pasted when the PDF is displayed on screen. A printout however would not show anything.
  2. The page could be containing "layers" (or "Optional Content Groups", /OCG elements), where one layer is set to be displayed on screen, but another (empty) layer is set to be used when printing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.