Yes or no questions are pretty rare here now that I think of it. My question is simply this:

When producing a PDF file with pdflatex or lualatex, is the original filename of an \includegraphics preserved in any way, shape or form in the final PDF?

The reason I'm asking is that I'm using some less-than-serious filenames but if the original authors of the works I'm referencing in these images saw the names, I would have to rely a bit too much on the ability of someone I don't know to take a joke.

The filename does not show up in plain text in the PDF file but neither does any of the text itself so that doesn't seem to be a reliable test. There is no tooltip or anything with any of the PDF readers I tried but again, that doesn't prove anything. Once this document is released, it would be too late to learn something about PDF files that I didn't know before.

PS: If you elaborated on your "yes" or "no", that would be very much appreciated ;)

Edit I think it is worth mentioning that this question might be relevant even to people who don't share my questionable sense of humor. Similar to undo information left in a Word file, seeing the original filename might reveal something about the author that they do not wish to reveal and are hardly aware of. Filenames like failed_attempt-6.png, study_plot_retouched.pdf or stand-in031.jpg are just some examples of filenames that might cast you in a strange light if uncovered by a faithful observer of your document ;)

  • if they find it out from such a detail then you have no way of not offending them.
    – percusse
    Commented Jan 14, 2014 at 21:03
  • @percusse I'm not sure if I know what you're getting at. I have no intention of letting anything of my feelings towards certain papers shine through and I'm confident I can manage that :) Still, calling an image robot_creepypants.jpg gives me a certain satisfaction that I cannot well describe but that I'm not willing to part from if I don't absolutely have to. Call me childish if you will :)
    – Christian
    Commented Jan 14, 2014 at 21:12
  • 2
    If you are worried, perhaps change \includegraphics{filename} to copy the file to /tmp/1 (using a counter to increment), and then actually include /tmp/1. Upon next invocation, it would include /tmp/2, etc. So you get to keep your "fun" file names, and the only numerical files are actually included. Commented Jan 14, 2014 at 21:15
  • 1
    I just meant that whoever looks for the filename in the pdf source is already offended and looking for proof :D
    – percusse
    Commented Jan 15, 2014 at 8:22
  • 2
    Calling a figure "why_jones's_method_is_crap.pdf" may be a handy figure title for use in your paper about "extending and improving" Jones's method. If Jones ends up reviewing your work and, because his eyesight is failing, being so old, uses a pdf screenreader that happens to read out the figure names from the file, your review might not be so favourable. Just a little parable.
    – Chris H
    Commented Jan 15, 2014 at 13:07

3 Answers 3


There are some cases, where the answer is "yes":

  • DVI files do not contain images, but their names are referenced. These names are needed and used by the DVI processor to find the images.

  • PDF images that are included by pdfTeX or LuaTeX: These engines store the file name in the additional key /PTEX.FileName and the information dictionary of the PDF images is remembered in key /PTEX.InfoDict. AFAIK it can only be avoided by changing the sources to omit these entries and recompiling.

    Other image file types are included without adding the file name. But meta data might be included and are preserved in case of JPEG files.

  • Image files, included by dvips: The PostScript image file is copied in the output PostScript file with a DSC header %%BeginDocument that contains the file name of the original PostScript image file. Also bitmap images are included with %%BeginDocument with the image file name prefixed by em:graph.


Meta data can be stripped from JPEG files using different tools, see How to remove EXIF data without recompressing the JPEG?. The accepted answer uses exiftool:

exiftool -all= image.jpg

Another way is using jpegtran from libjpg:

jpegtran -copy none -outfile new-image.jpg old-image.jpg
  • 1
    Ok, so for the direct route .tex.pdf the answer is "yes" if and only if the source image file was a .pdf itself but "no" if it was say a .png or a .jpg. Did I get that right?
    – Christian
    Commented Jan 14, 2014 at 21:21
  • 1
    in addition to that, when using pdftex or luatex, raster files such as .jpg org .png do not seem to be included with there filenames however I have only tried with files without metadata, I haven't tried with files with exif or other type of metadata.
    – ArTourter
    Commented Jan 14, 2014 at 21:24
  • @ArTourter Good point with the metadata. I'm not so subtle (and stupid) as to hide "funny" stuff in the metadata but it's certainly something worth keeping in mind in this context.
    – Christian
    Commented Jan 14, 2014 at 21:29
  • 1
    @Christian I was not really implying that you would keep comments in the metadata but rather that the software you use to create the image may indeed put the filename or other information in there without you knowing
    – ArTourter
    Commented Jan 14, 2014 at 21:34
  • 1
    So for professionally released pdfs you might want to run a script that goes through your text file and directory and changes all the image names to numeric sequences as part of your compile chain.
    – Canageek
    Commented Jan 14, 2014 at 21:50

If it's important to you to scrub the filenames of the files you are including then it's very risky to rely on the software that's building the PDF to scrub the filenames in all situations.

Even if you could know with 100% certainty that the software you're using is never, under any circumstances, including the source filenames in the output PDF file, any future update (even a minor update) to the software could change that behavior without notice.

For your own purposes, you could keep the "colorful" filenames for the images where you have them stored, but I would recommend that when you build the PDF, have a script/process that copies the source files to a temporary area with "sanitized" filenames, and build the PDF from there. Yes, it's a lot of extra work, but I think it'd be worth it just for the "peace of mind" factor.

  • +1 for bringing up a very good point. I'm far too lazy to actually do so, though. I mean copying the files is one thing but seding through my tex files, making absolutely sure I don't accidentally replace anything that's not actually an image filename ... I think I'd rather take the small risk of the filenames ending up in the document over trusting me not to mess up my scripting :)
    – Christian
    Commented Jan 15, 2014 at 11:55
  • 1
    @Christian you could look for (\\includegraphics[^{]*\{)([^}]*)(\}) and replace with $1newname$3 (regex built in to jEdit for me, so some tweaking may be needed especially in returning the groups. Personally if this was an issue I'd write something in python rather than scripting sed, but that says more about my shell scripting than anything else.
    – Chris H
    Commented Jan 15, 2014 at 12:26
  • @ChrisH Hey, watch your language, young man! ... oh sorry I misread. Thanks for the regexp in that case ;) Would probably have to randomize the escape level depending on shell, shell version and phase of the moon but other than that, this looks very airtight, great :) (Oh and sorry for the androcentrism in the beginning.)
    – Christian
    Commented Jan 15, 2014 at 14:32
  • @Christian :) despite being a recent convert to regexes I'm not zealous about them - this is the sort of task I like them for. Your (implicit) guess was right by the way.
    – Chris H
    Commented Jan 15, 2014 at 14:38
  • @ChrisH Sure they are great for these things. I'm just usually too lazy to get them right in more complicated cases like this one (with excluding a second { before } and stuff) because all the escaping and subtle differences from tool to tool are such a pain.
    – Christian
    Commented Jan 15, 2014 at 14:59

A slight duplicate but quick proof:

grep -ina spectral Thesis_master.pdf gives:

1482:/PTEX.FileName (./chap_somechap/figures/fig_somechap_spectral_lines.pdf)



or with:


(this surprised me - my skim-reading led me to believe the object dictionary would be compressed,and the pdf is 1/3 the size)

at the top of Thesis_master.tex, compiled via pdflatex. And that .pdf was indeed one of my figures (in an \included file).

Whether this would ever be visible to a non-suspicious user is of course another matter.

  • 1
    Ah, turning off compression as much as possible is a good idea to check for these things.
    – Christian
    Commented Jan 15, 2014 at 12:16
  • 4
    I'm going to go through all my colleagues pdf files doing grep -ina FileName bal.pdf and have lot's of fun! 3:D
    – Pouya
    Commented Jan 15, 2014 at 14:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .