# Nicely recover embedded images

I have the latex source code and final generated PDF, but not the image files. I'd like to modify the document, so I'd like to recover the image file so that I can recompile. I can (very slowly) manually recover the images by several methods, but I'd really like to have a tool that extracts the images and saves them with the same name that they were called from within the latex source.

For example, on linux with the pdfimages -j command, I can extract all images to ppm/pbm/jpeg formats, but it does not preserve the file name, so I would have to laboriously edit the source code.

I know that the output PDF retains some info about the file name, since the source document has lines like

\includegraphics{myImage}


and then if I do

grep myImage PDF_file.pdf


it says

Binary file PDF_file.pdf matches

• PDF files are actually text files, and some editors will treat them as such. I just ran a test program and found the following line in the PDF: /PTEX.FileName (C:/Program\040Files/MikTeX\0402.9/tex/latex/mwe/example-image.pdf) You could cut and paste the filename back into you source, and use an image editor to copy the cropped image. But unless you write a program in some other language to process the PDF including the /Filter /FlateDecode, you'll have to do it by hand. Jul 17, 2014 at 18:46
• Adobe Acrobat has an extract images option, but it only works on rasterized images. Jul 17, 2014 at 19:08
• @JohnKormylo, thanks for the ideas. But as I understand, PDF files can be a mixture of text and binary. I've looked at many of them with text editors before. I'm seeking an automated way here -- there are quite a few options if you don't need to do it in a time efficient manner. I'd also like to avoid expensive programs like Acrobat. Jul 17, 2014 at 20:57
• It's more like MIME than true binary. Jul 17, 2014 at 21:38

/PTEX.FileName (./tiger.pdf)

With a PDF library, the file name can be extracted as PDF string together with the page number. Also the information dictionary of the included PDF file is preserved. However, PDF images cannot be extracted by pdfimages. A PDF library with programming would be needed to get the XForm object together with its resources and to write the needed objects to a new PDF file.