View Single Post
Old 12-09-2012, 05:51 PM   #1
Junior Member
beco began at the beginning.
beco's Avatar
Posts: 1
Karma: 10
Join Date: Dec 2012
Device: Kobo Touch
Script to change pdf metadata (accented)

Hello guys,

First I just want to thank you Calibre Team, for the wonderful software you've made.

Now, I discovered that simple changing author and title in the calibre interface doesn't change the PDF metadata. That's a pitty, but here it is a simple solution, using pdftk (under Debian/Linux, but the toolkit also run under Windows/Mac).

First download and install PDFTK

I wrote this simple script. It has the option "-d" if you want to delete the backup.

Copy and save the following (without --- begin --- and --- end ---), save in a text file in a place your "PATH" includes, chmod it to +x (executable), and run as

$ myebook.pdf -d

--- Begin ---

# Copyright 2012, by Dr. Beco
# Gnu GPL licence.
# version 1.0, 05/dec/2012
# usage:
# pdffile.pdf [-d]
# -d delete old filename.old.pdf
# know bugs:
# solved bugs:

if [ "$1" == "" ]; then
echo Error: please tell me the pdf filename to open.
pdftk "$1" dump_data > metadatapdf.txt
cat metadatapdf.txt
echo "Edit tags? (y/n)"
read Ans
if [ "$Ans" == "y" ]; then
vi metadatapdf.txt
pdftk "$1" update_info metadatapdf.txt output "$1".new.pdf
mv "$1" "$1".old.pdf
mv "$1".new.pdf "$1"
if [ "$2" == "-d" ]; then
echo Deleting filename.old.pdf
rm "$1".old.pdf

# extra tip: find modified files using:
# ~/calibrelibrary/$ find . -regextype posix-extended -regex ".*\.epub|.*\.pdf" -newermt "2012-12-08 10:00" -printf "%Ay%Am%Ad%AH%AM%AS %f\n" | sort -n

--- End ---

The script will show you the current PDF tags. It will ask if you want to edit it or not. It will edit in vi if you choose "y", just save and quit.

And to include accented characters, use HTML CODE (found in this table: )

It took me some while to figure out how come "Bašan" was shown as "Ba─žan", but that's because PDF metadata does not accept UTF8.

Example of metadata for J˙lio Verne:

InfoKey: Author
InfoValue: J˙lio Verne

Also, I could use hexedit ( ) and manually insert the HEX code into the correct position. But that is too low level!

š = HEX E7 HTML: š
˙ = HEX FA HTML: ˙
ˇ = HEX F3 HTML: ˇ
and so on. Take a look at the table above.

I hope this serves to help someone.

beco is offline   Reply With Quote