Adobe eats hospitalised hedgehogs: Reader 2017 reports PDFs as damaged

The PDF file has many errors.

Output of ps2pdf (ghostscript):

   **** Error reading a content stream. The page may be incomplete.
               Output may be incorrect.
   **** Error: Form stream has unbalanced q/Q operators (too many q's)
               Output may be incorrect.
   **** Error reading a content stream. The page may be incomplete.
               Output may be incorrect.
   **** Error: File did not complete the page properly and may be damaged.
               Output may be incorrect.
   **** Error reading a content stream. The page may be incomplete.
               Output may be incorrect.
   **** Error: File did not complete the page properly and may be damaged.
               Output may be incorrect.
   **** Error: Recursive XObject detected, ignoring "Fm1", object number 51
               Output may be incorrect.
   **** Error: Recursive XObject detected, ignoring "Im8", object number 11
               Output may be incorrect.
   **** Error: Recursive XObject detected, ignoring "Fm3", object number 55
               Output may be incorrect.
   **** Error: Recursive XObject detected, ignoring "Fm3", object number 55
[...]

Evince reports:

 Error (3014): Incorrect number of arguments in 'sc' command

Xpdf reports the same error:

Syntax Error (2966): Incorrect number of arguments in 'sc' command

The error (sc) seems to be present in hedgehoghospital.pdf. It is s low-resolution bitmap image with a PDF wrapper.

The offending code:

stream
q Q q 0 0 139 142 re W n 0 sc /Gs1 gs 0 0 139 142 re f /Perceptual
ri /Gs2 gs q 139 0 0 142 0 0 cm /Im1 Do Q Q
endstream

I have not found the corresponding cs operator that defines the color space. Maybe, the default is /DeviceRGB with three parameters and 0 sc only uses one parameter.

Workarounds:

  • Maybe, you can find/generate a better version of hedgehoghospital.pdf, preferable a vector version.

  • Use of the bitmap data (PNG) without PDF wrapper:

The program pdfimages can be used to extract the bitmap data. Since, I do not have hedgehoghospital.pdf, I have used the third page (pdftk 5-kant4-fhei-p.pdf cat 3 output 3.pdf uncompress).

pdfimages `hedgehoghospital.pdf` h

This generates:

  • h-0000.ppm, the image data
  • h-0001.ppm, the transparency mask

Next, the image mask needs to be saved in grayscale format:

ppmtopgm <h-0001.ppm > h-0001.pgm

Then both images can be composed to the PNG file:

pnmtopng -alpha=333-0001.pgm <333-0000.ppm >hedgehog.png

Then, hedgehog.png can be used instead of hedgehog.pdf:

Result


For reasons which were never clear, I’ve also had problems displaying some Beamer PDF files with the Windows computers in classrooms, files created on my GNU/Linux box. In my experience, encrypting the PDF with qpdf seems to prevent that in many cases, and possibly it will work for you as well.

I don’t understand exactly how ‘qpdf’ helps, but its manual says, ‘QPDF does structural, content-preserving transformations on PDF files. It could have been called something like pdf-to-pdf.’ It allows for linearization, encryption, some repairs, etc.

The manual is on the long side, so here’s a quick start: you can encrypt a file with

qpdf --encrypt "" mypassword 128 --accessibility=y --extract=n --print=full --modify=none --cleartext-metadata --use-aes=y -- original-file.pdf encrypted-version.pdf