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 07-06-2010, 02:57 PM   #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: 7,514
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
epub2pdf script, now with GUI!

So... someone told me that I should create a GUI version of my epub2pdf.sh script, and after some time I bit the bullet and had a quick learning of python and Qt. This is a first working version of the thing. It not only generates PDF files from ePUB (if you have prince installed), but also creates thumbnails for use in the Cybooks (if you have convert installed). I think the interface is quite self-explanatory, at least for someone who knows more or less what the program is meant to do.

I'm sure there are many things that can be improved or added, and I'm open to suggestions. Something I'd like to do but I don't know how is having the output from prince redirected to some pop-up window (currently, the whole GUI just freezes while it runs), I'd appreciate any help with this.

Umm... as I said, it's a python script with PyQt4, so I guess both of them are needed. I have them in my linux box, and it works here, but I know nothing about MacOS or Windows.

Command line version
Calibre plugin version

EDIT (v 1.1):

Fixed detection of Book CSS
Included default CSS
Added tab to view CSS files in the ePUB
The generated PDF now includes correct title and author (or so I hope)

EDIT (v 1.2):

Fixed some issues in Windows
Fixed PDF metadata
Show only image files for possible covers
Show also HTML files in CSS viewer

EDIT (v 1.3):

Decode percent-encoded filenames
Fixed file path computation for non-UNIX filesystems (again)
Fixed metadata setting (truncate modified file on writing)
Fixed treatment of empty creators

EDIT (v 1.4):

There's apparently a bug in Prince that means links with directory separator do not work correctly in Windows, unless the command line is passed with unix/http-style paths. I hope it works fine with this version.
Attached Thumbnails
Click image for larger version

Name:	snapshot.png
Views:	2684
Size:	189.1 KB
ID:	54694  
Attached Files
File Type: zip epubutils-1.1.zip (6.9 KB, 1228 views)
File Type: zip epubutils-1.2.zip (7.1 KB, 1827 views)
File Type: zip epubutils-1.3.zip (7.2 KB, 850 views)
File Type: zip epubutils-1.4.zip (7.2 KB, 1719 views)

Last edited by Jellby; 12-26-2013 at 07:50 AM.
Jellby is offline   Reply With Quote
Old 07-06-2010, 04:08 PM   #2
nyrath
Addict
nyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfolded
 
nyrath's Avatar
 
Posts: 281
Karma: 52007
Join Date: Jun 2010
Device: nook
Yes, you will have to install PyQt as well as Python. It is available here:
http://www.riverbankcomputing.com/so.../pyqt/download

There is an automated installer for Windows, I fear that Mac OS users will have to read the install instructions.
nyrath is offline   Reply With Quote
Old 07-06-2010, 06:54 PM   #3
zelda_pinwheel
zeldinha zippy zeldissima
zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.
 
zelda_pinwheel's Avatar
 
Posts: 27,827
Karma: 921169
Join Date: Dec 2007
Location: Paris, France
Device: eb1150 & is that a nook in her pocket, or she just happy to see you?
wow. impressive and brilliant. thank you jellby.
zelda_pinwheel is offline   Reply With Quote
Old 07-09-2010, 12:24 AM   #4
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
Thanks for the new GUI version. Works for me.

I have one quick suggestion. The old version of the script came packaged with a default extra CSS you could use and modify to your preferences. I think it would be nice if there were something similar here. Perhaps if you clicked the CSS tab, you'd have something filled in for you by default, which you could modify if you wished: or perhaps, if that's too hands-on, something like that where it is all commented out but you could uncomment suggested options as you wished.

I don't think you can expect to provide a full GUI for people who know no CSS whatever to just choose all the CSS options there are. But especially when it comes to Prince-specific CSS like setting the page sizes and hyphenation options, etc., it would be nice to see a sample. Defaulting to letter-sized paper with very little margins isn't likely to help anyone.

Further along the same lines, you might even show the user the CSS files already contained in the ePub and let them modify them too directly, though I can imagine that would be difficult to implement.

Still, it's a great script as is. Thanks again!
frabjous is offline   Reply With Quote
Old 07-09-2010, 11:52 AM   #5
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,514
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by frabjous View Post
I have one quick suggestion. The old version of the script came packaged with a default extra CSS you could use and modify to your preferences.
I didn't include it here, but if you have a file named "default.css" in the $HOME/.epub2pdf directory, it will be read and used (it should appear as another tab in the GUI). I'll think about how to do this more obvious and user-friendly.

Quote:
Further along the same lines, you might even show the user the CSS files already contained in the ePub and let them modify them too directly, though I can imagine that would be difficult to implement.
Yes, that would be useful too, especially for examining the class names used in the ePUB... I'll think about it too, probably a read-only view of *.css files in the ePUB would be enough.
Jellby is offline   Reply With Quote
Old 07-12-2010, 01:10 PM   #6
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,514
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
I've updated the script with some improvements:
  • The generated PDF has now correct metadata.
  • If no $HOME/.epub2pdf/default.css exists, the "Default CSS" tab shows some default code
  • It's now possible to view (but not edit) all *.css files included in the ePUB.
Jellby is offline   Reply With Quote
Old 07-17-2010, 10:01 AM   #7
mmq
Junior Member
mmq began at the beginning.
 
mmq's Avatar
 
Posts: 3
Karma: 10
Join Date: Nov 2009
Device: Hanvon N516
I keep getting "NameError: global name 'meta' is not defined" on line 205 as an error. Anybody else?

My guess:

change line 205 from
Code:
      if meta.getAttribute("name") == "author":
to
Code:
      if child.getAttribute("name") == "author":
Seems to produce the right output (with author and title correctly set).

Thanks a ton for epub2pdf.sh and the new GUI!
mmq is offline   Reply With Quote
Old 07-17-2010, 11:27 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: 7,514
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by mmq View Post
My guess:

change line 205 from
Code:
      if meta.getAttribute("name") == "author":
to
Code:
      if child.getAttribute("name") == "author":
Good guess! It was one of the many bugs in the script That's only a problem if the first XHTML file has an author in the head, which is not always the case.
Jellby is offline   Reply With Quote
Old 07-25-2010, 06:23 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,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
Great work Jellby! Very nice indeed.

But you won't get many Windows users without an installer. For Windows, you should freeze the python script into an exe and bundle the dependencies into the installer.

Hey I'm perfectly satisfied with the bash script which I use on my Ubuntu box, I'm just saying the average Windows user needs a bit more hand-holding.
Valloric is offline   Reply With Quote
Old 07-25-2010, 06:31 AM   #10
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,514
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
And I don't say you are not right. But I don't even have a Windows computer to test it, so that's something I can't do at the moment
Jellby is offline   Reply With Quote
Old 07-26-2010, 02:32 PM   #11
nyrath
Addict
nyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfoldednyrath reads XML... blindfolded
 
nyrath's Avatar
 
Posts: 281
Karma: 52007
Join Date: Jun 2010
Device: nook
Yes, one can freeze the python script into a Windows exe by using a program called Py2Exe, but this is a complicated process not for the faint of heart. (the corresponding program for a Macintosh is Py2App)
nyrath is offline   Reply With Quote
Old 07-26-2010, 02:42 PM   #12
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Yeah, one of the biggest annoyances (from the perspective of a linux developer) is how painful it is to make "installers" for other platforms. I remember I started out with py2exe/py2app for calibre. But they proved insufficient as calibre grew and I ended up writing my own replacements for them.
kovidgoyal is offline   Reply With Quote
Old 09-08-2010, 03:16 PM   #13
viktorz
Junior Member
viktorz began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Sep 2010
Location: California
Device: PRS-505
Hello, and thanks for a script.

I have succesfully ran it under Windows 7, although got to change couple lines to fix some windows-specific issues (like back-slash paths and file permissions).

But I have a problem with links (like endnotes). Looks like Prince resolved relative urls in the source like "notes.html#note_1" to a absolute paths of temporary files like "c:\users\blabla\temp\blabla\notes.html#note_1 " which obviously doesn't work in the resulting pdf. Is it a common problem? Or is it just me? Or my particular book? Or my Windows 7? Can we somehow tell Prince to make all links internal?
Attached Files
File Type: zip epubutils_win.zip (6.7 KB, 995 views)

Last edited by viktorz; 09-08-2010 at 03:23 PM.
viktorz is offline   Reply With Quote
Old 09-09-2010, 10:41 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: 7,514
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by viktorz View Post
I have succesfully ran it under Windows 7, although got to change couple lines to fix some windows-specific issues (like back-slash paths and file permissions).
Argh. It seems I missed the path separation issue in one place, and I overlooked this piece of information about the NamedTemporaryFile procedure:

"Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later)."

I think I've fixed it now, could you try the new 1.2 version? You may have to modify the "prince" filename again, or include in your system's path.

Quote:
But I have a problem with links (like endnotes). Looks like Prince resolved relative urls in the source like "notes.html#note_1" to a absolute paths of temporary files like "c:\users\blabla\temp\blabla\notes.html#note_1 " which obviously doesn't work in the resulting pdf. Is it a common problem? Or is it just me? Or my particular book? Or my Windows 7? Can we somehow tell Prince to make all links internal?
It doesn't happen to me, intra-ePUB links are transformed into intra-PDF links. Is the "notes.html" file included in the ePUB (and in the <spine>)? If it isn't, it's not passed to Prince, and it's not included in the PDF. If it is, and you see the contents in the PDF, but it's only the links that are not working: can I see a sample ePUB?
Jellby is offline   Reply With Quote
Old 09-09-2010, 03:11 PM   #15
viktorz
Junior Member
viktorz began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Sep 2010
Location: California
Device: PRS-505
Quote:
Originally Posted by Jellby View Post
I think I've fixed it now, could you try the new 1.2 version?
No, it is not quite right yet. Please see file attached, specifically the method "file" that I have changed. See, I just replaced the slash? That makes it work, otherwise reading from zip fails because of the wrong slash:
Code:
Traceback (most recent call last):
  File "C:\Utils\epub2pdf\epubutils_2.py", line 493, in loadFile
    self.fileLoaded(unicode(filename))
  File "C:\Utils\epub2pdf\epubutils_2.py", line 497, in fileLoaded
    self.epub = ePUB(filename)
  File "C:\Utils\epub2pdf\epubutils_2.py", line 66, in __init__
    self.readMetadata()
  File "C:\Utils\epub2pdf\epubutils_2.py", line 110, in readMetadata
    pages = int(math.ceil(zfile.getinfo(file).compress_size/1024.0))
  File "C:\Python27\lib\zipfile.py", line 818, in getinfo
    'There is no item named %r in the archive' % name)
KeyError: "There is no item named u'OPS\\\\cover.xhtml' in the archive"
Attached Files
File Type: zip epubutils_win.zip (6.9 KB, 793 views)

Last edited by viktorz; 09-09-2010 at 03:18 PM.
viktorz 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
GUI bug? edbro Calibre 2 06-19-2010 09:55 AM
has anyone tried epub2pdf ? frabjous Workshop 2 01-04-2010 02:01 PM
Gui confusements. brewt Calibre 8 12-30-2008 12:16 PM
epub2pdf touch_elango Introduce Yourself 2 10-25-2008 10:36 AM
Mobi2Mobi GUI Batch Jad Kindle Formats 8 10-22-2008 07:22 AM


All times are GMT -4. The time now is 02:44 PM.


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