I am generating a latex file with many \includegraphics commands from a program. The image files change from run to run. The latex file might, for example, look like the one in this question. Occasionally an image file that I receive is corrupted. I can eliminate nearly all such situations by checking the size of the image file and emitting some vertical space instead of the \includegraphics command should the the image file be too small to reasonably be the sort of image I am expecting; however, a very small number of corrupted image files are larger. In that case pdflatex stops with an error message. All my image files are .jpg files. I believe that jpegtran on UNIX will fix most of these and I could pass every jpeg through that but I am concerned about the impact on runtime if I do that and also there could still be a very few that that does not address. Is there a way to handle this? Basically I need something like: "include a jpg file using includegraphics without generating an error and if that fails then emit some vertical space otherwise the includegraphics can stand".
Asked
Active
Viewed 8,873 times
1
user1189687
- 1,953
1 Answers
7
The error you get:
Error: pdflatex (file corrupt.jpg): reading JPEG image failed
==> Fatal error occurred, the output PDF file is not finished!
Even with nonstopmode active indicates to me that this is a pdfTeX specific issue which occurs in the special PDF-related code of the binary which is responsible for reading JPEG files and not a real TeX error.
Therefore there seems to be nothing you can do in (La)TeX itself. If you can't manually sort out the corrupted files then I would try to write a script which compiles a small test document for each image and checks if the compilation was successful.
Martin Scharrer
- 262,582
mwe'sexample-image-a). – Werner Sep 21 '12 at 21:56jpegtranon them all in advance but its not really that convenient and also I am not sure that that would necessarily catch them all although it probably would catch most. I would prefer if all this were self contained in the report so I don't have to start messing with external processes. – user1189687 Sep 21 '12 at 22:00\includegraphicswhich uses a local\nonstopmodeto make LaTeX keep going after an error. I'm not 100% sure if this will stop all driver errors as well. – Martin Scharrer Sep 22 '12 at 08:10\documentclass{article} \nonstopmode \usepackage{graphicx} \begin{document} \includegraphics{corrupt.jpg} \end{document}withpdflatex -interaction=nonstopmode mytest.texbut it still stopped. The first line of output ofpdflatex --versiongivespdfeTeX 3.141592-1.21a-2.2 (Web2C 7.5.4); however, the same procedure did work under Windows Vista. In that casepdflatex --versiongivesMiKTeX-pdfTeX 2.8.3563 (1.40.10) (MiKTeX 2.8). – user1189687 Sep 22 '12 at 13:46Error: pdflatex (file corrupt.jpg): reading JPEG image failed ==> Fatal error occurred, the output PDF file is not finished!. Its as ifnonstopmodehad not been turned on. – user1189687 Sep 22 '12 at 14:50