25

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?

  • 2
    Is it possible to take an example of damaged (hedgehog) PDF file from somewhere to analyse? – Przemysław Scherwentke Jun 11 '18 at 23:59
  • 1
    I’ve had stray problems displaying Beamer PDF files on the Windows computers in classrooms; encrypting the PDF with qpdf seems to prevent that in many cases, for reasons I don’t understand. BTW, here be hedgehogs. – Thérèse Jun 12 '18 at 0:12
  • 1
    No, just a password that prevents altering the PDF. No password needed to open it. Use like this: qpdf --encrypt "" mypassword 128 --accessibility=y --extract=n --print=full --modify=none --cleartext-metadata --use-aes=y -- original-file.pdf encrypted-version.pdf – Thérèse Jun 12 '18 at 0:17
  • 1
    cfrees.files.wordpress.com/2018/06/5-kant4-fhei-p.pdf @PrzemysławScherwentke – cfr Jun 12 '18 at 0:24
  • 1
    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.) This minor aspect has been discussed before -- further reading: Is the filename of an image preserved in the final PDF? – Chris H Jun 12 '18 at 13:14
23

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

  • Thanks. I also have a PNG, so I think I can just delete the PDF and force use of the PNG. Has Adobe's viewer got a lot fussier? I've used the same images in these slides for ages and I've never had the hedgehog disappear before. I suspect the cat PDF is also bitmap, but it doesn't mind that? – cfr Jun 12 '18 at 3:32
  • The wrapper for the cat does not use sc. – Heiko Oberdiek Jun 12 '18 at 4:13
  • I guess that's not small-caps in this context? – cfr Jun 13 '18 at 2:29
  • 1
    @cfr sc refers to the PDF operator that causes the trouble in the hedgehog case. – Heiko Oberdiek Jun 13 '18 at 5:04
7

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

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.