[Tex/LaTex] Adobe eats hospitalised hedgehogs: Reader 2017 reports PDFs as damaged

acrobatbeamergraphicspdfviewers

I create slides for teaching on a GNU/Linux machine and test in Okular. I then transfer the files to university storage so that I can use them in class. This has been working well. However, today, Adobe Reader 2017 reported 2 of the 3 PDFs as damaged. In both cases, the slides displayed fine except that all images of hospitalised hedgehogs were missing. The space was there, but no hedgehog. All other images displayed fine. All text displayed fine.

I just re-transferred the 'damaged' PDFs to my laptop and the files are identical to those I uploaded. I also double-checked that the originals include the hopsitalised hedgehog everywhere they should. Okular shows everything is fine.

Adobe Reader XI reports corrupted PDF for pdfTeX compiled combination beamer + overlay + textblock + includgraphics seems related, but it is difficult to be sure and the comments say the problem can't be reproduced.

The image causing the problem for me is included as PDF. But the slides also use a picture of a cat, also included as PDF, and not a problem.

If I read the content of the PDF as text, I can see the file path for the PDF images. (I was surprised by this – I didn't realise the original file path would be included.)

The only two differences I can see in the treatment of the two images is that

  1. the hedgehog is included multiple times at different sizes, whereas the cat image is included only once at a single size;
  2. the hedgehog is saved into a box at one of the sizes and used as a 'logo' on various slides, whereas the cat is not.

However, I am not sure how to tell whether either, both or neither of these is the problem or not.

Creating an MWE is tricky because I have no way of knowing when the problem has gone away, since I only use Windows in the classrooms I teach in and don't have it available otherwise. (If necessary, I can use a lab computer for testing, but that's a pain.)

Basically, a schematic of my code would look like this:

\pdfminorversion=7
\documentclass{beamer}
\begin{document}
\begin{Form}
\begin{frame}
  \includegraphics[width=\textwidth]{hedgehog}
\end{frame}
\begin{frame}
  \includegraphics[width=.225\textwidth]{hedgehog}
\end{frame}
\begin{frame}
  \includegraphics[width=\textwidth]{cat}
\end{frame}
\end{Form}
\end{document}

The logo code I'm using looks like this

\newsavebox{\hhl}
\sbox{\hhl}{%
        \includegraphics[scale=.5]{hedgehogs/hedgehoghospital}}
\newcommand*\hhllogo{%
  \logo{\usebox{\hhl}}% followed by code to create an attribution at the bottom of slides
}
\newcommand*\nologo{%
  \logo{}% followed by code to clear the attribution from the bottom of slides
}
\hhllogo

Would either the inclusion of a PDF image at multiple sizes or the placement of the PDF using Beamer's \logo{} be expected to create issues for Adobe Reader 2017? I should note that this code worked fine with earlier versions of Reader, as I've not had this problem before and these slides are virtually unchanged from previous years.

If the answer to the above is 'No', how can I best debug this in order to figure out what I need to avoid to get things working correctly?

Best Answer

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