08-14-2006, 08:34 AM | #1 |
Enthusiast
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
|
Cropping PDFs
I was thinking that it would be nice if iRex allowed us to add some cropping information to the manifest file.
It would be great if, on a per document basis, we could add something like (hope this comes through OK) ... <croptop>20</croptop><cropbottom>20</cropbottom> <cropleft>50</cropleft><cropright>50</cropright> The PDF renderer could generate a larger page that is then cropped by the specified number of pixels before displaying. This would allow the user to reduce the amount of white space around the pages by as much as they prefer. I'm suggesting this for the case where one only has the PDF (I have a lot of reference books I've purchased in PDF format that I don't have the source for). |
08-14-2006, 08:44 AM | #2 |
Addict
Posts: 302
Karma: 116
Join Date: May 2006
Device: Iliad, dude!
|
I found that all PDF's I tried so far could be cropped manually by editing the MediaBox.
For example, an A4 PDF will contain something like Code:
/MediaBox [ 0 0 595 842 ] Code:
/MediaBox [ 50 50 545 792 ] Under Linux, I'd do it using sed: Code:
sed 's/0 0 595 842/50 50 545 792/g' <book.pdf >cropped.pdf |
Advert | |
|
08-14-2006, 08:46 AM | #3 | |
Pac-Man caught my iLiad.
Posts: 807
Karma: 3595
Join Date: Apr 2006
Location: Germany; next to Baltic Sea
Device: Boox Max Lumi, iRex iLiad (RIP)
|
Quote:
Cropping of pdf files was dicussed earlier in this forum, I don't know, what the result was [existence of an OS program]. Uh, just change the mediabox tag. This is so easy? Cool! Last edited by yokos; 08-14-2006 at 08:49 AM. |
|
08-14-2006, 08:51 AM | #4 | |
Enthusiast
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
|
Quote:
Thanks for the information. |
|
08-14-2006, 09:09 AM | #5 |
Pac-Man caught my iLiad.
Posts: 807
Karma: 3595
Join Date: Apr 2006
Location: Germany; next to Baltic Sea
Device: Boox Max Lumi, iRex iLiad (RIP)
|
Well, I tried this; I didn't worked for me. Adobe Reader can't read this file anymore. Perhaps I did it the wrong way.
|
Advert | |
|
08-14-2006, 09:13 AM | #6 | |
Addict
Posts: 302
Karma: 116
Join Date: May 2006
Device: Iliad, dude!
|
Quote:
|
|
08-14-2006, 12:00 PM | #7 |
Enthusiast
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
|
Well, I had a certain amount of success with the MediaBox hacking approach.
However, for some of my PDFs, while this change seems to have had the desired effect when looking at them in Acrobat, after transfer to the Iliad, there seems to be extra white space on the left and right, somewhat negating the desired result. I've not worked out yet how the ones that work well differ from those that exhibit the extra white space, but I'll keep working at it. At least I've been able to get rid of extraneous white space at top and bottom in every document, which does make a difference. |
08-14-2006, 12:04 PM | #8 |
iLiad freak
Posts: 339
Karma: 243
Join Date: Apr 2006
Location: Mallorca, Spain
Device: iRex iLiad
|
The iLiad fits the pdf into its screen respecting the document's proportions, so maybe that's why you're still seeing white side margins.
edit: ie. cropping the side margins on a 15cm long pdf will make absolutely no difference. |
08-14-2006, 12:07 PM | #9 | |
Enthusiast
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
|
Quote:
Code:
cropLeft = ARGV[0].to_i cropRight = ARGV[1].to_i cropTop = ARGV[2].to_i cropBottom = ARGV[3].to_i originalPath = ARGV[4] croppedPath = originalPath.sub(/\.pdf$/, " (cropped).pdf") File.open(originalPath, "rb") do |input| pdf = input.read pdf.gsub!(/\/MediaBox \[\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*\]/) do n1 = $1.to_i + cropLeft n2 = $2.to_i + cropTop n3 = $3.to_i - cropRight n4 = $4.to_i - cropBottom "/MediaBox [#{n1} #{n2} #{n3} #{n4}]" end File.open(croppedPath, "wb") { |output| output.write pdf } end I just wanted to get something working. I'll clean it up later, once I have the details worked out a bit better. |
|
08-14-2006, 12:50 PM | #10 | |
Addict
Posts: 222
Karma: 110
Join Date: Jun 2006
Location: Malmo, Sweden
Device: iLiad, Sony PRS-505, Kindle Paperwhite & Oasis
|
Quote:
Of course, if your editor changes the original newlines behind your back, it will mess up thing even more. PDF files should be treated as binary files. Last edited by ath; 08-14-2006 at 01:05 PM. |
|
08-14-2006, 01:09 PM | #11 | |
Addict
Posts: 302
Karma: 116
Join Date: May 2006
Device: Iliad, dude!
|
Quote:
"Save a copy" in acroread doesn't fix it... Hmmmmmmmmmmmmmmmm Have to think about this. |
|
08-14-2006, 01:51 PM | #12 |
Guru
Posts: 607
Karma: 2157
Join Date: Oct 2005
Device: NCR3125, Nokia 770,...
|
Also a pdfcrop utility exist in the TeX packages, but it generates files bigger.
|
08-14-2006, 02:02 PM | #13 |
Zealot
Posts: 124
Karma: 177
Join Date: Jul 2006
Location: Bochum, Germany
Device: MP2K, iLiad
|
PDF-Cropping on OSX
I don't know if anybody mentioned if, but on MacOSX you can just open your PDF in preview.app, select an area on a page, see if the content-area on the other pages are complete and have preview crop all pages using the same stencil.
Then use "save as..." to save a cropped copy. 5 mouseclicks. k2r |
08-14-2006, 05:53 PM | #14 | |
Enthusiast
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
|
Quote:
|
|
08-14-2006, 05:58 PM | #15 | |
Enthusiast
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
|
Quote:
I'm not overly worried about the files being larger, unless we're talking an order of magnitude. The 100 or so MB in the Iliad is enough to hold a lot of reference material. My largest book is only about 8MB and that's over 800 pages worth. I'll give that a go tonight. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cropping Multiple Files | SpyKiIIer | 16 | 12-07-2012 01:09 AM | |
Cropping .pdfs with Briss and converting with Calibre | mrslecavalier | Amazon Kindle | 6 | 07-13-2010 08:53 PM |
cropping pdf with preview | wang960 | Sony Reader | 2 | 05-05-2009 10:28 AM |
Yet another PDF cropping tool | sjvr767 | iRex | 7 | 02-14-2009 08:04 AM |
yet another cropping tool | moggie | 4 | 01-16-2009 05:42 AM |