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

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
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, 668 views)

Last edited by DaveNB; 07-13-2008 at 06:08 PM. Reason: Listed known bugs.
DaveNB is offline   Reply With Quote
Old 07-21-2008, 11:33 AM   #2
sammykrupa
Reader of the Reader
sammykrupa doesn't littersammykrupa doesn't litter
 
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!
sammykrupa is offline   Reply With Quote
Old 12-21-2008, 10:26 PM   #3
kf6gpe
Member
kf6gpe began at the beginning.
 
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!
kf6gpe is offline   Reply With Quote
Old 03-02-2009, 08:28 AM   #4
akirk
Junior Member
akirk began at the beginning.
 
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
So now, if the device is connected, the file is auto-transfered to it. Makes it even better for me
akirk is offline   Reply With Quote
Old 03-02-2009, 10:24 AM   #5
pthwaite
Fanatic
pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.
 
pthwaite's Avatar
 
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
pthwaite is offline   Reply With Quote
Old 03-02-2009, 10:28 AM   #6
akirk
Junior Member
akirk began at the beginning.
 
Posts: 5
Karma: 22
Join Date: Mar 2009
Device: prs500
Quote:
Originally Posted by pthwaite View Post
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?
Well, maybe just try it prs500 is actually a command line program, so I am not sure if it can write to Cybook.

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:/
Check the output of that command, maybe it says something another device string for the mountpoint.
akirk is offline   Reply With Quote
Old 03-02-2009, 12:16 PM   #7
pthwaite
Fanatic
pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.
 
pthwaite's Avatar
 
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.
pthwaite is offline   Reply With Quote
Old 03-02-2009, 02:35 PM   #8
akirk
Junior Member
akirk began at the beginning.
 
Posts: 5
Karma: 22
Join Date: Mar 2009
Device: prs500
Quote:
Originally Posted by pthwaite View Post
I try the original script and it goes away and appears to do something, but no output appears on the desktop?
Start up a Terminal and type
Code:
pdf2lrf
What does it say? For me that program resides in
Code:
/usr/bin/pdf2lrf
You can type
Code:
ls /usr/bin/pdf2lrf
to check if it is there. If not, you might have a problem with your installation. If it shows up, you can try to open up the workflow in Automator and change the pdf2lrf call to include the path.
akirk is offline   Reply With Quote
Old 03-03-2009, 12:27 PM   #9
pthwaite
Fanatic
pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.
 
pthwaite's Avatar
 
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.
pthwaite is offline   Reply With Quote
Old 03-03-2009, 12:30 PM   #10
akirk
Junior Member
akirk began at the beginning.
 
Posts: 5
Karma: 22
Join Date: Mar 2009
Device: prs500
Quote:
Originally Posted by pthwaite View Post
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.
Well, the 4 pages you see are for the PDF that is generated and handed to the script. Try opening up the .workflow file from DaveNB by double clicking it and change the reference to pdf2lrf to /usr/bin/pdf2lrf and save it. Then try again.
akirk is offline   Reply With Quote
Old 03-03-2009, 04:52 PM   #11
pthwaite
Fanatic
pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.
 
pthwaite's Avatar
 
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
pthwaite is offline   Reply With Quote
Old 03-03-2009, 07:36 PM   #12
akirk
Junior Member
akirk began at the beginning.
 
Posts: 5
Karma: 22
Join Date: Mar 2009
Device: prs500
Quote:
Originally Posted by pthwaite View Post
Nothing, running Console gives:
03/03/2009 21:51:07 Automator Runner[2879] Error while processing arguments
I had that a lot myself when trying to enhance the script, too

Quote:
Originally Posted by pthwaite View Post
You don't need Xcode installed do you?
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
as the first line in the script, make it executable
Code:
chmod 755 test.tcsh
and then run it with a PDF as parameter
Code:
./test.tcsh "my pdf file.pdf"
This will give you more useful output than through Automator.

This is getting pretty detailed, maybe we should to continue in direct msging?
akirk 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
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


All times are GMT -4. The time now is 07:34 AM.


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