3

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.

Hans
  • 1,281
  • 1
  • 20
  • 44

1 Answers1

2

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:

http://130.15.24.88/exiftool/forum/index.php?topic=4779.0

http://130.15.24.88/exiftool/forum/index.php?topic=4595.0

Glutanimate
  • 21,393