Sunday, October 22, 2017

ghostscript crashes when embedding fonts in a pdf: caused by png file

I'm using Ubuntu 14.04. I had this problem with a book. I prepared LaTeX source, say book.tex, use pdflatex book to make a book.pdf, and then needed to embed the fonts to send the file to the printer. To do this I usually use the sequence of terminal commands:
pdf2ps book.pdf
(which outputs book.ps) and
ps2pdf -dPDFSETTINGS=/prepress book.ps book-w-embedded-fonts.pdf

But having used this many times without problems, and through several revisions of the text, it crashed one day while executing the last command. The command ps2pdf invokes ghostscript, or gs, with suitable arguments, so this appears as a crash of gs, and the crash dump is placed in /var/crash with a name that tells you it was gs that crashed.

The problem remained after I installed all software upgrades.

To isolate the problem, I used a bisection search on the source, and it turned out that the crash was caused by the inclusion of a png-format graphic file, using \includegraphics from the LaTeX package graphicx. (This was tedious to locate, because there was no problem with pdflatex, I had no idea of the nature of the problem, and for each step of the binary search I had to re-run the font-embedding commands, which take minutes.)

I'm not sure what the problem was with the png file, but I just used gimp to make an equivalent jpg file, and used that instead, and that got me past the problem. The crazy thing about this is that there are other png files included in the source, and they were similarly generated (using Sage) and, even stranger, the same file worked in an earlier draft. It seems unlikely that it was corrupted, since I was able to load it into gimp and make the jpg from it.

The main reason for this post is to flag that it might be useful to check any png-format files, if you ever encounter the same problem.

It would be more satisfactory if I could understand the problem, rather than just walking around and past it. It appears that ps2pdf with this flag is not just adding font data to the pdf file, but is also doing something with the embedded graphics. Can anyone answer these questions:
1. Does pdflatex put a full native pdf description of the included graphics into the output book.pdf, or does it rely on an external graphics engine to render graphics?
2. Same question for pdflatex followed by pdf2ps: what is in the postscript file, in relation to the included graphics? I notice that book.ps is about 5 times larger than book.pdf.

No comments:

Post a Comment