After I asked this question I was wondering if there is a way to whether create a script or find a new software that automatically set's a pdf's title tag to the assigned name.

The idea is that after you execute the script or program on the pdf it automatically change the pdf's title tag to be the same as the pdf's name.


exiftool would be my tool of choice for this. First make sure exiftool is installed:

sudo apt-get install libimage-exiftool-perl

Now for the interesting part, assigning the Metadata tag to your filename. exiftool can source the content of metadata fields from other information such as the filename. It can also perform basic text processing steps on the sourced information.

With that in mind we can construct a command that will read the filename, remove the extension, and assign it as the content of both Title metadata fields found in pdf files (PDF:Title and XMP-dx:Title):

exiftool '-PDF:Title<${filename;s/\..*?$//}' '-XMP-dc:Title<${filename;s/\..*?$//}' file.pdf

Quick breakdown of the command sequences:

  • -PDF:Title< – assign PDF-Title field to what follows after the <

  • ${filename;s/\..*?$//} – use filename and remove extension via a regular expression

Further reading:

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.