Page 1 of 1

Renaming PDF document titles from filename

Posted: 08 May 2015 14:05
by gcmartin
I have a bunch of recipes collected from various places and stored as PDF files which I want to transfer to my e-reader but although the filename for these recipes properly describes the recipe, the document titles are quite random. Is it possible to script a batch rename for these files so that they appear correctly in my e-reader (i.e. make the document title in the metadata match the filename). Here's hoping ......

Re: Renaming PDF document titles from filename

Posted: 08 May 2015 14:33
by highend
Possible...

I don't have much time atm, so you would need Calibre (http://calibre-ebook.com/download_portable) for this script to work...

The portable version of it is enough. Install this portable version and remember it's path.

Code: Select all

$ebookMeta = "D:\Users\Highend\Tools\Calibre\Calibre\ebook-meta.exe";

    $files = get("SelectedItemsPathNames", "|");
    foreach($file, $files) {
        $baseName = getpathcomponent($file, "base");
        if ($baseName) {
            run """$ebookMeta"" ""$file"" --title=""$baseName""", , 1, 1;
        }
    }
Change the first line to the path of your ebook-meta.exe!

Let's say you installed it to drive D:\
Calibre created a subfolder named "Calibre Portable" automatically, so the new path for the "$ebookMeta" variable would be:
D:\Calibre Portable\Calibre\ebook-meta.exe

After that, save the script, go to your e-book folder and select all files which titles should be changed. Make backups first and try it with e.g. two of them. If it works, fine, do it for all others.

If you find a better command line utility that writes title metadata into different ebook formats... Let me know.

Re: Renaming PDF document titles from filename

Posted: 08 May 2015 15:12
by gcmartin
Thanks for a quick reply - I'll try it out and see how it goes :tup:

Re: Renaming PDF document titles from filename

Posted: 08 May 2015 16:35
by gcmartin
Perfect! I hadn't discovered ebook-meta in Calibre.

http://manual.calibre-ebook.com/cli/ebook-meta.html

Very useful as it obviously it opens up several possibilities for renaming PDF's as well as other e-books.

Many thanks.