Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 12-09-2012, 05:51 PM   #1
beco
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
http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

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

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

$ pdfmeta.sh myebook.pdf -d

--- Begin ---

#!/bin/bash
#
# Copyright 2012, by Dr. Beco
# Gnu GPL licence.
#
# version 1.0, 05/dec/2012
#
# usage:
# pdfmeta.sh 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.
else
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
fi
fi
fi


# 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:
http://web.forret.com/tools/charmap.asp?show=ascii )

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 ( http://linux.die.net/man/1/hexedit ) and manually insert the HEX code into the correct position. But that is too low level!

é = HEX E9 HTML: é
ç = 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
beco is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ePUB + PDF creation script Trouhel ePub 30 07-28-2012 09:02 AM
PDF to EPUB batch/script conversion ? smallhagrid Conversion 5 06-14-2011 06:33 PM
Script to download pdf-newspapers like ftd? ganymede Recipes 1 03-11-2011 09:04 AM
JetBook PDF antialiasing script syrex314 Ectaco jetBook 7 05-18-2010 07:23 PM
A script to make iLiad show mobi metadata. Format C: iRex 4 09-23-2008 10:45 AM


All times are GMT -4. The time now is 10:50 PM.


MobileRead.com is a privately owned, operated and funded community.