View Single Post
Old 07-13-2008, 06:56 AM   #1
DaveNB
Connoisseur
DaveNB has a complete set of Star Wars action figures.DaveNB has a complete set of Star Wars action figures.DaveNB has a complete set of Star Wars action figures.DaveNB has a complete set of Star Wars action figures.
 
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
Just drag a copy of this Automator script (included in the .zip file attached to this post, unzip it first or it won't work) into the "PDF Services" folder in your "Library" folder (located in your Home directory). I'd suggest you first open it up in Automator to have a look at it's code to make sure that it does what you want it to (ie. you may want to change the destination for the LRF file creation or some of it's margin settings, etc) and more importantly: to make sure it isn't doing something malicious!! Remember, all Automator scripts/applications have the potential to harm to your local user account so due diligence is recommended.

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
Attached Files
File Type: zip OSX Workflow-Create Sony Reader LRF V1.0.zip (43.1 KB, 389 views)

Last edited by DaveNB; 07-13-2008 at 06:08 PM. Reason: Listed known bugs.
DaveNB is offline   Reply With Quote