11-22-2009, 07:49 AM | #1 |
frumious Bandersnatch
Posts: 7,516
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Script for converting ePUB to PDF using Prince
Some time ago I wrote the epub2pdf script to render ePUB files into PDF, using the excellent abilities of Prince.
Well, I think it's about time to have it with its own thread in the ePUB forum It is tried in Linux only, but I guess it should work in Windows under Cygwin too, and in MacOs. The script uses unzip, XMLstarlet and Prince. 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 (default is "default.css") -S "style.css" Use "style.css" as highest-priority stylesheet Stylesheets will be searched in the current directory first, and then in ~/.epub2pdf -v Verbose output -h Show this help 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. These are not going to be used in the normal ePUB rendering, only when processing with Prince, so you can use everything supported by Prince (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. The ePUB files I've uploaded here have all this epub2pdf-specific style. Current version is 3.1 GUI version Calibre plugin version Last edited by Jellby; 12-26-2013 at 07:50 AM. |
11-26-2009, 06:19 PM | #2 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
I've said it before, but I'll say it again... This script is fantastic.
Works great on linux anyway. Has anyone tried it with Cygwin, though? I have my doubts. |
01-01-2010, 11:22 AM | #3 |
Created Sigil, FlightCrew
Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
|
OK, feedback coming your way.
First off, bloody amazing tool! I can finally get justified text on my PRS-505. I love epub, but I'm not a big fan of the ADE renderer on the 505. Secondly, using "-v" showed I was missing "pdftk" and "recode". sudo apt-get install fixed that, but you may want to add it to the list of dependencies. Thirdly, I hate the horizontal ruler and the page counter at the top. I know I can edit "default.css" (and I have), but it would be wise to provide a switch for this. Lastly, you could turn this into a very nice little OSS project with a little bit of effort: switch from bash to python, include all the dependencies in a package/installer (I recommend InstallJammer) and provide it stand-alone for the three major platforms. Host it on google code or something. Don't forget to note that because of Prince it could only be used for personal uses and that they'd have to buy a license for commercial ones. It would be very nice indeed. |
01-01-2010, 11:51 AM | #4 | |||
frumious Bandersnatch
Posts: 7,516
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
Quote:
But anyone is welcome to do that, converting to python (or whatever) should be relatively easy indeed. Hey, you could even add it to Sigil Quote:
|
|||
01-01-2010, 12:19 PM | #5 |
Created Sigil, FlightCrew
Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
|
|
01-22-2010, 08:18 PM | #6 |
Created Sigil, FlightCrew
Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
|
Jellby, I've noticed that my output PDF's are somehow screwing up the italics... I'm using embedded fonts in the epub file (roman, bold, italic) and they get picked up just fine, but it seems Prince slants the italic text even though it uses the italic font I embedded.
So, the italic font is used, but slanted some more. It's as if Prince is trying to create a "fake" italic font, but since it also uses the real italic font, the results look ugly and weird. Is this a bug in Prince or in the bash script/default.css? BTW the epub book displays just fine in ADE. |
01-22-2010, 11:23 PM | #7 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
It would probably help to see the relevant portions of default.css and the tags used in the html. The problem might be with Prince but I'd bet there was a way around it; perhaps by declaring the true italic as its own font-family, but calling it with font-style: normal rather than font-style: italic.
|
01-23-2010, 03:57 AM | #8 | |
frumious Bandersnatch
Posts: 7,516
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
|
|
01-23-2010, 09:46 AM | #9 | |
Created Sigil, FlightCrew
Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
|
Quote:
But it's good to know they're working on fixing this bug. |
|
01-26-2010, 05:33 AM | #10 |
Connoisseur
Posts: 65
Karma: 36
Join Date: Jan 2010
Device: none
|
wow, I did not even know this existed (new to ePub myself) - will put some new sparkle in my rusty PRS-505. thank you!
|
07-11-2010, 08:02 PM | #11 |
Member
Posts: 14
Karma: 10
Join Date: Feb 2010
Device: Jetbook
|
Just to say I have used this script quite extensively with excellent results. I use Linux on the desktop and an Ectaco Jetbook (5").
I have found that public domain epubs from Feedbooks have worked really well. Others that I have purchased and converted to epub are mostly good. The TOC is the most interesting bonus. If it is present the script seems to haul it in particularly well. I am a little foggy about how the settings can be changed and have tended to run with the default. Thanks for making this available. --Tony |
07-12-2010, 01:13 PM | #12 |
frumious Bandersnatch
Posts: 7,516
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Welcome to MobileRead, tonhou
I'm glad you like the script, you may find the new GUI version easier to work with, at least you see the CSS stylesheets that are being used. |
08-01-2012, 08:27 AM | #13 |
Junior Member
Posts: 6
Karma: 10
Join Date: Aug 2012
Device: none
|
Problem with footnotes
Hi there,
first I want to thank you for publishing your great script. It is the best solution for converting epub to pdf I found on the web (and i searched long time). Now I use your script for the following task: I export a dokuwiki to epub and then convert it with your script. Works fine but one problem: When I click the footnotes which were generated for external links, I get a error message: "epub2pdf/OEBPS/footnotes.html': No such file or directory" errors from console: Code:
prince: OEBPS/title.html:3: error: Misplaced DOCTYPE declaration prince: OEBPS/title.html:4: error: htmlParseStartTag: misplaced <html> tag prince: OEBPS/footnotes.html:167: error: EntityRef: expecting ';' prince: OEBPS/footnotes.html:167: error: EntityRef: expecting ';' prince: OEBPS/footnotes.html:239: error: EntityRef: expecting ';' prince: OEBPS/footnotes.html:239: error: EntityRef: expecting ';' prince: OEBPS/footnotes.html:240: error: EntityRef: expecting ';' prince: OEBPS/footnotes.html:240: error: EntityRef: expecting ';' prince: OEBPS/footnotes.html: error: could not load input file Code:
@font-face { font-family: serif; src: local("Georgia") } @font-face { font-family: sans-serif; src: local("Verdana") } @font-face { font-family: monospace; src: local("Courier New") } @page { size: 21cm 29.7cm; margin: 20mm 20mm 20mm 20mm; @top-left { font-size: 60%; font-style: italic; border-bottom: solid thin black; margin-bottom: 1mm; content: string(booktitle); } @top-center { font-size: 60%; font-style: italic; border-bottom: solid thin black; margin-bottom: 1mm; content: string(chaptertitle); } @top-right { font-size: 50%; border-bottom: solid thin black; margin-bottom: 1mm; content: counter(page) "/" counter(pages); } } @page:first { margin: 20mm 20mm 20mm 20mm; @top-left { border-width: 0; margin: 0; content: normal; } @top-center { border-width: 0; margin: 0; content: normal; } @top-right { border-width: 0; margin: 0; content: normal; } } body { font-size: 8.0pt; font-family: serif; text-align: justify; hyphens: auto; prince-image-resolution: auto; } img{ max-width: 100%; } h1, h2, h3, h4, h5, h6 { hyphens: none; } :lang(it), :lang(es) { hyphenate-before: 3; hyphenate-after: 3; } Thanks and kind Regards! |
08-01-2012, 10:40 AM | #14 |
frumious Bandersnatch
Posts: 7,516
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
It looks like there's a problem with the HTML source. Can you post the epub file? Have you tried validating the epub with epubcheck or Sigil?
|
08-05-2012, 03:07 PM | #15 |
Junior Member
Posts: 6
Karma: 10
Join Date: Aug 2012
Device: none
|
Hi Jellby,
I can not post the whole epub because it contains top secret information ( ) but I exported only one site to show the problem to you. You can get the epub here: https://www.dropbox.com/s/c5epp1owz4..._08-47-48.epub And here is is what I get from the script: https://www.dropbox.com/s/tqk47wa039d8iye/testOut.pdf The errors are the same as i mentioned before. Thanks for your efforts! |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
converting pdf to epub | Gagan | ePub | 65 | 06-28-2017 11:57 PM |
Converting Sanskrit PDF to epub | sriniamble | Calibre | 17 | 11-25-2010 06:10 AM |
Error converting to PDF from EPub and PRC | gauravj | Calibre | 3 | 05-24-2010 02:07 AM |
Problem converting pdf to epub | smartin | Calibre | 3 | 05-02-2010 06:55 AM |
Help with converting PDF to epub | neilmarr | Sigil | 6 | 11-14-2009 09:26 AM |