View Single Post
Old 09-14-2009, 11:33 AM   #11
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,516
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
OK, here it is, the first version of epub2pdf, a bash script for converting ePUB books to PDF. Since it's a bash script, it needs bash (doh!), that means linux users will have it easy, for MacOS users it will be probably similar, but Windows users will have to install Cygwin for the moment (although it should be easy to translate the script to Windows...)

I've tried it with some ePUBs of my own, as well as generated by Calibre, and uploaded by Zelda and Abecedary, and it seems to work great! These are the usage notes:

Code:
epub2pdf.sh [options] input.epub output.pdf

Where the options are:
  -s "style.css"  Use "style.css" as stylesheet instead of the default ~/.epub2pdf/default.css
  -v              Verbose output
  -h              Show this help
So you see, it's fairly easy. Place the included "default.css" file in ~/.epub2pdf and it will be used automatically for all conversions, or you can specify other css file (or modify default.css at your will), it will be searched in ~/.epub2pdf first (so you can keep different "profiles" there).

I added a feature to use a book-specific stylesheet if found. This stylesheet should be included in the .epub and referenced thus:

1.- Include a .css with rules and selectors for Prince XML. These are not going to be used in the normal ePUB rendering, only when processing with Prince XML, so you can use everything supported by Prince XML (use !important to override the standard css rules).

2.- As with every file you include in the epub, there must be an entry in the <manifest> (in the .opf file).

3.- Add a <meta name="prince-style" content="XXXXX"> to the <metadata> block of the .opf file, where "XXXXX" is the id of the above .css file.

That's all, epub2pdf will use this .css file included in the .epub in addition to the default.css or whatever you use. As an example, I'm updating the The Picture of Dorian Gray upload.

Please, try it and tell me what you think!

EDIT: Script updated to version 2.0 (now it uses XMLStarlet to process the metadata and "pdf-style" has been changed to "prince-style").

EDIT: Now updated to version 3.0

EDIT: The script is now available here.

Last edited by Jellby; 11-22-2009 at 07:52 AM.
Jellby is offline   Reply With Quote