How to edit pdf metadata from command line?

Give exiftool a try, it is available from the package libimage-exiftool-perl in the repositories.

As an example, If you have a pdf file called drawing.pdf and you want to update its metadata, Use the utility, exiftool, in this way:

exiftool -Title="This is the Title" -Author="Happy Man" -Subject="PDF Metadata" drawing.pdf

For some reason the Subject entered ends up in the keywords field of the metadata in the pdf file. not a problem in some cases, even desirable, however, this may be problematic, evince and the nautilus metadata previewer do not show this but Adobe Acrobat viewer and PDF-XChange viewer does.

The program will create a backup of the original file if you do not use the; -overwrite_original switch, this means a duplicate will exist in the folder where the updated pdf is. From example above; a file named ; drawing.pdf_original will be created.

use the overwrite switch at your own risk, my suggestion is not to use it and script something to move this file to a better location just in case.


You can edit metadata by using pdftk. Check out update_info parameter. As for data file, below is an example:

InfoKey: Title
InfoValue: Mt-Djing: multitouch DJ table
InfoKey: Subject
InfoValue: Dissertation for Master degree
InfoKey: Keywords
InfoValue: DJing, NUI, multitouch, user-centered design
InfoKey: Author
InfoValue: Pedro Lopes

(Source)


Using Ghostview

Install ghostscript with:

$ sudo apt install ghostscript

Create a file named pdfmarks with similar content:

[ /Title (Document title)
  /Author (Author name)
  /Subject (Subject description)
  /Keywords (comma, separated, keywords)
  /ModDate (D:20061204092842)
  /CreationDate (D:20061204092842)
  /Creator (application name or creator note)
  /Producer (PDF producer name or note)
  /DOCINFO pdfmark

then combine this pdfmarks file with a PDF, PS or EPS input file:

gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf original.pdf pdfmarks

Source: http://milan.kupcevic.net/ghostscript-ps-pdf/