![]() |
#1 |
Connoisseur
![]() ![]() ![]() ![]() Posts: 86
Karma: 399
Join Date: Jun 2007
Device: Nook, Sony PRS-500, Nokia 770 (FBReader)
|
OS X Printing Workflow/Automator action for use with Calibre
I was thinking the other day I should automate some of the command line steps that I use repeatedly to create LRF documents for my Sony Reader. Specifically I wanted to be able to "print" directly to a LRF file formatted for the Sony Reader.
Sure you could set up custom paper sizes and a print profile for generating .PDF files formatted for the Sony Reader, but the results are inconsistent and often look terrible (not to mention are slow to load/turn pages and have reduced contrast due to the way PDF's are rendered on the Sony Reader). Based on the fact that OS X renders all it's print jobs in PDF format before sending them to the printer and also based on the fact that Calibre does a pretty darned good job of reflowing PDF's, I came up with the following Automator script that executes the following command line utility (assuming you've already installed Calibre): Code:
cd $HOME/Desktop # This is where the LRF file will be saved while ( $# ) pdf2lrf --enable-autorotation --left-margin=2 --right-margin=2 --top-margin=2 --bottom-margin=2 --page-break-before-tag='\$' --blank-after-para "$1" shift end Then, from any application that supports printing, you can select the "Create Sony Reader LRF" option in the drop down menu triggered by the "PDF" button that appears in every print dialogue box (when you select Print from the File menu or when you type <command>+<p>). The resulting LRF file will show up on your Desktop. I'm not sure if anyone else has already figured out how to do this, but it works great for me. No more saving to HTML or printing to a PDF file, then manually typing the command line html2lrf/pdf2lrf commands. Now it'll all happen quickly and painlessly from the Print dialogue box. You can also use this Automator action as a folder action or create a self contained Applescript Application/Bundle that'll covert any PDF dropped into it. I use it to create LRF's from my daily RSS news feed for reading on the road and for creating quick little LRF's from web pages that I'm viewing (web pages that have a printer friendly format come out nicely). Feel free to modify and change this little Automator script to your liking. I'm going to try to figure how to add some more intelligence to it (ie. lets you specify the Author, Title, etc). Not all of the formatting is perfect on some pages. Things to fix: 1) There are some pages that render with missing line breaks. 2) I'd like to remove all page breaks (placed in the PDF's as a part of the formatting to fit on your set paper size) which the "--page-break-before-tag='\$'" is supposed to do (but isn't doing consistently). The next version may do the conversion in 3 steps: 1) PDF -> HTML conversion 2) Strip and modify the HTML to fix problems listed above using sed/grep and other text processing tools 3) Create the LRF It still need some work, but as a quick and dirty way to make LRF's, it's pretty good. Enjoy, Dave Last edited by DaveNB; 07-13-2008 at 06:08 PM. Reason: Listed known bugs. |
![]() |
![]() |
![]() |
#2 |
Reader of the Reader
![]() ![]() Posts: 103
Karma: 107
Join Date: Apr 2006
Device: Sony Reader PRS-500
|
Thanks
Thanks, this might even allow the Reader to work with my mother!
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Member
![]() Posts: 14
Karma: 10
Join Date: Dec 2008
Device: PRS-700
|
Aces, thank you!! I was just sitting down to figure out something like this. I'll give this a try and see how it works. Cheers!
|
![]() |
![]() |
![]() |
#4 |
Junior Member
![]() Posts: 5
Karma: 22
Join Date: Mar 2009
Device: prs500
|
Thanks DaveNB! Just found out about this.
I have added something to the code to transfer the generated lrf directly to the device (in my case a prs500, not tested with others): Code:
cd $HOME/Desktop # This is where the LRF file will be saved while ( $# ) pdf2lrf --enable-autorotation --left-margin=2 --right-margin=2 --top-margin=2 --bottom-margin=2 --page-break-before-tag='\$' --blank-after-para "$1" set n=`basename "$1" .pdf` prs500 cp "$n.lrf" prs500:/Data/media/books/ shift end ![]() |
![]() |
![]() |
![]() |
#5 |
Fanatic
![]() ![]() ![]() ![]() ![]() Posts: 597
Karma: 430
Join Date: Aug 2008
Location: Ellesmere Port, UK
Device: DR1000S Sony PRS505 iPad iPhone
|
I assume (as I have a Cybook) to run the same script for Mobi output you would just change the pdf2lrf to pdf2mobi and change the lrf to mobi and Cybook elsewhere?
Then, as you say it would save a lot of messing around. Howard |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Junior Member
![]() Posts: 5
Karma: 22
Join Date: Mar 2009
Device: prs500
|
Quote:
![]() Code:
$ prs500 cp Usage: prs500.py cp [options] source destination Copy files to/from the device One of source or destination must be a path on the device. Device paths have the form prs500:mountpoint/my/path where mountpoint is one of / or card:/ |
|
![]() |
![]() |
![]() |
#7 |
Fanatic
![]() ![]() ![]() ![]() ![]() Posts: 597
Karma: 430
Join Date: Aug 2008
Location: Ellesmere Port, UK
Device: DR1000S Sony PRS505 iPad iPhone
|
Ho hum...
I try the original script and it goes away and appears to do something, but no output appears on the desktop? Now, I don't have calibre in the Applications directory, I run it from an external drive (Mac mini with small drive). Could it be that it cannot find Calibre? If so where do I edit it to point to the Calibre installation. Sorry to appear dim. |
![]() |
![]() |
![]() |
#8 | |
Junior Member
![]() Posts: 5
Karma: 22
Join Date: Mar 2009
Device: prs500
|
Quote:
Code:
pdf2lrf Code:
/usr/bin/pdf2lrf Code:
ls /usr/bin/pdf2lrf |
|
![]() |
![]() |
![]() |
#9 |
Fanatic
![]() ![]() ![]() ![]() ![]() Posts: 597
Karma: 430
Join Date: Aug 2008
Location: Ellesmere Port, UK
Device: DR1000S Sony PRS505 iPad iPhone
|
Well mine is in:
/usr/bin as well and it lists it, after all Calibre can find it. However I cannot find any output generated when I run it. ie printing this web page using it suggests it has printed 4 pages, but they don't appear anywhere. Then again it doesn't ask for a file name output. |
![]() |
![]() |
![]() |
#10 | |
Junior Member
![]() Posts: 5
Karma: 22
Join Date: Mar 2009
Device: prs500
|
Quote:
|
|
![]() |
![]() |
![]() |
#11 |
Fanatic
![]() ![]() ![]() ![]() ![]() Posts: 597
Karma: 430
Join Date: Aug 2008
Location: Ellesmere Port, UK
Device: DR1000S Sony PRS505 iPad iPhone
|
Nothing, running Console gives:
03/03/2009 21:51:07 Automator Runner[2879] Error while processing arguments Oh well. I'll have to dig deeper. You don't need Xcode installed do you? regards |
![]() |
![]() |
![]() |
#12 | |
Junior Member
![]() Posts: 5
Karma: 22
Join Date: Mar 2009
Device: prs500
|
Quote:
![]() I do have it installed, but I doubt you need it. Just briefly, how I did the debugging, was this: Put the contents from the script in the .workflow file into a .tcsh file, insert Code:
#!/bin/tcsh Code:
chmod 755 test.tcsh Code:
./test.tcsh "my pdf file.pdf" This is getting pretty detailed, maybe we should to continue in direct msging? ![]() |
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calibre Ebook Viewer Printing | tom95521 | Calibre | 2 | 04-17-2010 01:28 PM |
Calibre as part of InDesign epub workflow | GRiker | Calibre | 3 | 09-18-2009 12:44 PM |
Question on Workflow | emellaich | Calibre | 1 | 07-16-2009 11:08 AM |
Trying to establish a workflow | macaddicted | Workshop | 0 | 05-07-2009 01:43 AM |
Opinion on workflow (and enhancing it) - research-type workflow | TheDarkTrumpet | Which one should I buy? | 8 | 03-02-2009 10:41 AM |