Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 11-22-2009, 08:49 AM   #1
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: 6,253
Karma: 4801165
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Lightbulb 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
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. 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
Attached Files
File Type: zip epub2pdf.zip (2.9 KB, 1477 views)

Last edited by Jellby; 12-26-2013 at 08:50 AM.
Jellby is offline   Reply With Quote
Old 11-26-2009, 07:19 PM   #2
frabjous
Wizard
frabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
frabjous's Avatar
 
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.
frabjous is offline   Reply With Quote
 
Advertisement
Old 01-01-2010, 12:22 PM   #3
Valloric
Created Sigil, FlightCrew
Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.
 
Valloric's Avatar
 
Posts: 1,978
Karma: 350515
Join Date: Feb 2008
Device: Sony Reader PRS 505
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.
Valloric is offline   Reply With Quote
Old 01-01-2010, 12:51 PM   #4
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: 6,253
Karma: 4801165
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by Valloric View Post
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.
Well... the script works fine without them, they're only used for setting the metadata. They are listed as optional dependencies at the top of the script.

Quote:
Lastly, you could turn this into a very nice little OSS project with a little bit of effort: [...]
I'm afraid your "little bit of effort" is too much for me I lack the knowledge and energy for efficiently creating, testing and maintaining something like what you suggest. I know it's probably easier than it seems, but even so, I'm not motivated enough...

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:
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.
I know, I know... I expected each user to "develop" his/her own default.css, and only provided mine as an example. Of course, sharing CSS files is always an option
Jellby is offline   Reply With Quote
Old 01-01-2010, 01:19 PM   #5
Valloric
Created Sigil, FlightCrew
Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.
 
Valloric's Avatar
 
Posts: 1,978
Karma: 350515
Join Date: Feb 2008
Device: Sony Reader PRS 505
Quote:
Originally Posted by Jellby View Post
Hey, you could even add it to Sigil
I would if Prince XML were open source.
Valloric is offline   Reply With Quote
Old 01-22-2010, 09:18 PM   #6
Valloric
Created Sigil, FlightCrew
Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.
 
Valloric's Avatar
 
Posts: 1,978
Karma: 350515
Join Date: Feb 2008
Device: Sony Reader PRS 505
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.
Valloric is offline   Reply With Quote
Old 01-23-2010, 12:23 AM   #7
frabjous
Wizard
frabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
frabjous's Avatar
 
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.
frabjous is offline   Reply With Quote
Old 01-23-2010, 04:57 AM   #8
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: 6,253
Karma: 4801165
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by Valloric View Post
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.

[...]

Is this a bug in Prince or in the bash script/default.css?
It's a bug in Prince, see here.
Jellby is offline   Reply With Quote
Old 01-23-2010, 10:46 AM   #9
Valloric
Created Sigil, FlightCrew
Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.
 
Valloric's Avatar
 
Posts: 1,978
Karma: 350515
Join Date: Feb 2008
Device: Sony Reader PRS 505
Quote:
Originally Posted by Jellby View Post
It's a bug in Prince, see here.
Thanks Jellby. I actually managed to figure out last night that Prince determines whether to apply faux bold or italic to a font based on the font properties in the file itself, not how the font is invoked.

But it's good to know they're working on fixing this bug.
Valloric is offline   Reply With Quote
Old 01-26-2010, 06:33 AM   #10
Sullivan
Connoisseur
Sullivan began at the beginning.
 
Sullivan's Avatar
 
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!
Sullivan is offline   Reply With Quote
Old 07-11-2010, 09:02 PM   #11
tonhou
Member
tonhou began at the beginning.
 
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
tonhou is offline   Reply With Quote
Old 07-12-2010, 02:13 PM   #12
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: 6,253
Karma: 4801165
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.
Jellby is offline   Reply With Quote
Old 08-01-2012, 09:27 AM   #13
Heisenberg
Junior Member
Heisenberg began at the beginning.
 
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
my config css looks like this:
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;
}
I'm not very familiar to prince so if someone could help me I would really appriciate!!!

Thanks and kind Regards!
Heisenberg is offline   Reply With Quote
Old 08-01-2012, 11:40 AM   #14
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: 6,253
Karma: 4801165
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?
Jellby is offline   Reply With Quote
Old 08-05-2012, 04:07 PM   #15
Heisenberg
Junior Member
Heisenberg began at the beginning.
 
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!
Heisenberg is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
converting pdf to epub Gagan ePub 56 10-12-2014 04:22 PM
Converting Sanskrit PDF to epub sriniamble Calibre 17 11-25-2010 07:10 AM
Error converting to PDF from EPub and PRC gauravj Calibre 3 05-24-2010 03:07 AM
Problem converting pdf to epub smartin Calibre 3 05-02-2010 07:55 AM
Help with converting PDF to epub neilmarr Sigil 6 11-14-2009 10:26 AM


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


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