Skip to content
Unix Server Solutions
  • Server
  • Apple
  • Database
  • Ubuntu
  • Linux

Ubuntu – How to edit pdf metadata from command line

command linemetadatapdf

I need a command line tool for editing metadata of pdf-files.

I'm using a Aiptek MyNote Premium tablet for writing my notes and minutes on this device, import them later and convert them to pdf automatically with a simple script using inkscape and ghostscript.

Is there any command line tool to add some categories to the pdf's metadata, so i can find the pdf later (e.g. with gnome-do) by categories?

Update: I tried the solution with pdftk and it works, but it seems that gnome-do doesn't take care of pdf-metadata. Is there a way to get gnome-do to do that?

Best Answer

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.

Related Solutions

Ubuntu – How to search pdf files by their metadata

I would recommend that you use the excellent program called recoll, available in the repositories, to index your documents and then use it to search.

recoll can be used from the commandline with the -t switch like this;

recoll -t author:"Christopher Negus"

where the string in quotes is the author of a pdf document of interest, see below;

enter image description here

The recoll Gui is fast and intuitive;

enter image description here

See more here; http://www.lesbonscomptes.com/recoll/

You may also use a specialized e-book management system like Calibre,again available from the repositories.

Ubuntu – Command line tool to crop PDF files

I would suggest you take a look at PDFcrop.

If you wish to crop a pdf with left, top, right and bottom margins of 5, 10, 20, and 30 pt (points), then run

pdfcrop --margins '5 10 20 30' input.pdf output.pdf

in terminal. To actually crop something away, use negative values in the argument for crop. For example,

pdfcrop --margins '-50 -50 -50 -50' input.pdf output.pdf

crops 50 pts from the left, top, right, bottom (in this order).

If you run only the command pdfcrop input, it will output a file titled input-crop.pdf with zero margins. I find this very handy when including pdf illustrations in documents.

Cropping multiple files

Unfortunately, pdfcrop cannot crop multiple files at the time. It is however easy to write a script that will crop all pdfs in the folder the script is located in.

Create a new empty file, and call it something.sh. Open it with a text editor and insert the following:

#!/bin/bash
for FILE in ./*.pdf; do
  pdfcrop "${FILE}"
done

Save it, and close. Then right click the file, go to Properties > Permissions and check the field Allow executing file as program. Now close the dialog. Run the script by double clicking it and choosing Run in Terminal. And new, zero-margin cropped version of all pdfs with suffix -crop will now be printed in the folder. If you want margins or other things, you can of course just open the script and add arguments after pdfcrop.

Related Question
  • Ubuntu – How to search pdf files by their metadata
  • Ubuntu – Command line tool to crop PDF files
  • Ubuntu – How to outline fonts in a PDF (or eps) file
  • Ubuntu – Zotero cannot retrieve metadata from PDF
  • Ubuntu – How to remove all metadata from a file (e.g. pdf)