0

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 ...

MrMills
  • 151
  • 11

1 Answers1

0

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.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Thanks - I'll experiment with https://smarnach.github.io/pyexiftool/ because I'm more familiar with Python. – MrMills Dec 01 '19 at 15:51
  • Two things to point out. First, odds are that you don't need to script exiftool and it usually will be very slow to do so as exiftool's biggest performance hit is its startup time. ExifTool has very power batch ability by itself. Check out the [ExifTool Forums](https://exiftool.org/forum) if you need help creating a command. Second, due to the way ExifTool changes the metadata, any changes it makes are reversible. See the third paragraph under [PDF Tags](https://exiftool.org/TagNames/PDF.html). – StarGeek Dec 01 '19 at 16:56