0
votes

Apologies if this has been asked before. I'm after a way of batch editing the metadata (title, author, keywords mainly) of a lot of PDF files. I can edit them individually but I've got over 100 files to edit (for Calibre) and I can't find any programs that will allow me to do it.

Is it possible to write a script using EXIFTOOL or Ghostscript?

Update : This is what I've got so far ...

import exiftool
import csv

files = csv.csv2sequence('metadata.csv')

for file in files:
    filename     = file[0]
    set_title    = '-title='    +file[1]
    set_author   = '-author='   +file[2]
    set_creator  = '-creator='  +file[3]
    set_producer = '-producer=' +file[4]
    with exiftool.ExifTool() as et:
        et.execute(set_title,filename)
        et.execute(set_author,filename)
        et.execute(set_creator,filename)
        et.execute(set_producer,filename)

... with the metadata stored in a csv file. However, I get this error when I run it ...

TypeError: sequence item 0: expected a bytes-like object, str found

... from the exiftool.py file. Not sure what this is ...

1

1 Answers

0
votes

Ghostscript doesn't edit PDF metadata, not at all. At most it produces a new PDF file where the metadata is what you want, but the content (ie the actual PDF operations) will not be the same, and some 'metadata' may be lost, because Ghostscript's pdfwrite device doesn't preserve it from the input into the output.

Apparently exiftool can alter just the metadata so you would do better to use that. I'm reasonably sure you could write a shell script to do whatever it is you want to do.