Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > Workshop

Notices

Reply
 
Thread Tools Search this Thread
Old 01-29-2011, 02:04 PM   #1
mark121
Junior Member
mark121 began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Nov 2010
Device: nook
CUPS driver for EPUB?

My Linux system has a print driver that allows one to "print" to a PDF file on disk, instead of an actual printer. I have seen discussions here about if it is possible to write a printer-driver that would generate an *epub file. From what I was able to follow, the problem is that PDF is page-oriented, as a printer is, while EPUB is not. However, it is possible to convert PDF to EPUB, using software such as Calibre. So, would it not be possible to pipe the output of the CUPS-PDF driver through a PDF-to-EPUB converter to get an EPUB printer?
mark121 is offline   Reply With Quote
Old 01-29-2011, 04:30 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
What discussions were those? Can you provide a link?

This may or may not be technically possible. However, PDF is generally one of the worst file formats to convert to ePub, so if it worked with PDF as an intermediary, it's probably not a good idea.

You're almost certainly much better off trying to convert the source files directly. What kinds of files are these, anyway?
frabjous is offline   Reply With Quote
Advert
Old 01-29-2011, 05:56 PM   #3
mark121
Junior Member
mark121 began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Nov 2010
Device: nook
Thanks for the quick reply! I don't have the link to the older thread I was looking at, but I was following the rule of "do a search before asking a question", and found a series of exchanges between Calibre author Goyal and a user about the technical problems with such a conversion.

My specific situation is that I have access to some online textbooks, that allow printing but do not allow saving to disk. So, using the CUPS-PDF driver, I "print" the pages to a PDF file, which I would then like to convert to EPUB to read on my laptop/desktop/Droid. I could also print-to-disk as a PostScript file, but I suspect that wouldn't be much different from printing to PDF.
mark121 is offline   Reply With Quote
Old 01-29-2011, 09:44 PM   #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
CUPS printing system is more or less built around postscript, so it's pretty much unavoidable that PostScript files, or at least postscript output will be involved at some point, and PDFs aren't much different than PostScript files, as you note. (CUPS-PDF simply calls Ghostscript's ps2pdf to convert PostScript to PDF.)

Well, playing around, I did more or less figure out how to this, printing to PDF then use calibre for conversion afterwards.

Of course, (1) you'd get identical results simply printing to PDF in the normal way and then importing/converting using calibre's GUI, and (2) given your situation, with a textbook, I'm about 99% sure you'd be better off just printing to PDF and leaving it as a PDF. (Ideally there should be options for setting the page sizes to a PDF to a smaller size so it looks better on your screen.)

However, if you really want to, here's what I did. This may vary a bit depending on Linux distribution.
  1. Install the cups-pdf pacakge, and install a "Generic-CUPS-PDF-Printer" in the usual way. (The details here would depend on distribution, but I doubt you'll have trouble finding instructions for this if you google it. (Note, I think you need a real virtual printer, and not just a PDF option under "Print to File".)
  2. Create a post-processing script. You might, for example, name it /home/<yourname>/bin/cups-pdf_script.sh -- mine looks like this:
    Code:
    #!/bin/bash
    xhost +local
    CURRENT_PDF="${1}"
    CURRENT_USER="${2}"
    DISPLAY=:0.0
    export DISPLAY
    XAUTHORITY=/home/${CURRENT_USER}/.Xauthority
    export XAUTHORITY
    PDFNAME="$(zenity --file-selection --save --confirm-overwrite --title 'Save PDF as...')"
    mv "$CURRENT_PDF" "$PDFNAME"
    if zenity --question --text "Create ePub?" ; then
       EPUBNAME="$(zenity --file-selection --save --confirm-overwrite --title 'Save EPUB as...')"
       ebook-convert "$PDFNAME" "$EPUBNAME"
    fi
    (This requires the zenity program for GTK dialog-boxes, which usually comes with GNOME, as well as the ebook-convert program which comes with calibre. Basic idea is stolen from here.)
  3. Make that file executable:
    Code:
    chmod a+x /home/<yourname>/bin/cups-pdf_script.sh
  4. Now make a copy of your cups-pdf settings:
    Code:
    sudo cp /etc/cups/cups-pdf.conf{,-old}
    And then edit them:
    Code:
    sudo vim /etc/cups/cups-pdf.conf
    (For "vim", substitute your favorite text editor: gedit, nano, emacs, etc., as you prefer.)
  5. Find the line:
    Code:
    #PostProcessing
    And change it to:
    Code:
    PostProcessing /home/<yourname>/bin/cups-pdf_script.sh
    (Be sure to remove the # at the beginning.)
  6. Restart the CUPS Daemon, which depending on distribution may be done either with:
    Code:
    sudo /etc/init.d/cupsd restart
    Or with:
    Code:
    sudo /etc/rc.d/cups restart
Now when you print to the Generic CUPS-PDF printer, after it asks you where to save the PDF, it'll follow up by asking if you want to create an ePub as well, and if you click yes, and pick a location, it will call calibre to convert the PDF.

This worked for me on Arch Linux running GNOME. It may need to be tweaked for your distribution or set up. You may also want to customize the script, including the options for ebook-convert (see here).

But again, I'm not sure how that's better than simply using calibre's GUI, or using a properly sized PDF.

Last edited by frabjous; 01-29-2011 at 09:47 PM.
frabjous is offline   Reply With Quote
Reply

Tags
driver, epub, pdf, printer


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Are you a better than average driver? Adoby Lounge 126 09-10-2010 01:52 PM
Kindle 3 driver? lunixer Calibre 11 09-02-2010 09:04 AM
Seriously thoughtful If you're a driver .... scary ! GeoffC Lounge 6 04-18-2010 12:28 AM
Driver for Win XP idle OpenInkpot 6 02-04-2010 07:59 AM
Windows driver Thrasymachus OpenInkpot 9 07-31-2009 10:57 PM


All times are GMT -4. The time now is 04:10 AM.


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