Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > More E-Book Readers > iRex

Notices

Reply
 
Thread Tools Search this Thread
Old 08-14-2006, 08:34 AM   #1
harryo
Enthusiast
harryo began at the beginning.
 
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).
harryo is offline   Reply With Quote
Old 08-14-2006, 08:44 AM   #2
ali
Addict
ali doesn't litterali doesn't litter
 
ali's Avatar
 
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 ]
in one or several places. I just adjusted the four values - to crop 50 points from each border, I'd change that to
Code:
/MediaBox [ 50 50 545 792 ]
Both acroread and xpdf will honor that. That way, you can even crop page numbers / chapter headings and such away.

Under Linux, I'd do it using sed:
Code:
sed 's/0 0 595 842/50 50 545 792/g' <book.pdf >cropped.pdf
Under Windows, you'd have to open the pdf in notepad or something (don't know if that harms binary streams in the pdf)
ali is offline   Reply With Quote
Advert
Old 08-14-2006, 08:46 AM   #3
yokos
Pac-Man caught my iLiad.
yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.
 
yokos's Avatar
 
Posts: 807
Karma: 3595
Join Date: Apr 2006
Location: Germany; next to Baltic Sea
Device: Boox Max Lumi, iRex iLiad (RIP)
Quote:
Originally Posted by harryo
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>
Nice idea! Yepp, not all iLiad users have access to commercial software like Acrobat to crop pdf files.

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.
yokos is offline   Reply With Quote
Old 08-14-2006, 08:51 AM   #4
harryo
Enthusiast
harryo began at the beginning.
 
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
Quote:
Originally Posted by ali
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 ]
in one or several places. I just adjusted the four values - to crop 50 points from each border, I'd change that to
Code:
/MediaBox [ 50 50 545 792 ]
Both acroread and xpdf will honor that. That way, you can even crop page numbers / chapter headings and such away.
Fantastic! I'll try whipping up a Ruby script to do this automatically for me.

Thanks for the information.
harryo is offline   Reply With Quote
Old 08-14-2006, 09:09 AM   #5
yokos
Pac-Man caught my iLiad.
yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.yokos can teach chickens to fly.
 
yokos's Avatar
 
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.
yokos is offline   Reply With Quote
Advert
Old 08-14-2006, 09:13 AM   #6
ali
Addict
ali doesn't litterali doesn't litter
 
ali's Avatar
 
Posts: 302
Karma: 116
Join Date: May 2006
Device: Iliad, dude!
Quote:
Originally Posted by yokos
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.
What did you do, and how?
ali is offline   Reply With Quote
Old 08-14-2006, 12:00 PM   #7
harryo
Enthusiast
harryo began at the beginning.
 
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.
harryo is offline   Reply With Quote
Old 08-14-2006, 12:04 PM   #8
ElaHuguet
iLiad freak
ElaHuguet doesn't litterElaHuguet doesn't litterElaHuguet doesn't litter
 
ElaHuguet's Avatar
 
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.
ElaHuguet is offline   Reply With Quote
Old 08-14-2006, 12:07 PM   #9
harryo
Enthusiast
harryo began at the beginning.
 
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
Quote:
Originally Posted by ali
What did you do, and how?
I don't know how ali did it, but I used this piece of Ruby code
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 don't have a reference for the /MediaBox parameters, so I did it by trial and error. In reality, I didn't take much care, just ran the program and fiddled the four values until I got what looked good for each document.

I just wanted to get something working. I'll clean it up later, once I have the details worked out a bit better.
harryo is offline   Reply With Quote
Old 08-14-2006, 12:50 PM   #10
ath
Addict
ath doesn't litterath doesn't litter
 
Posts: 222
Karma: 110
Join Date: Jun 2006
Location: Malmo, Sweden
Device: iLiad, Sony PRS-505, Kindle Paperwhite & Oasis
Quote:
Originally Posted by ali
I found that all PDF's I tried so far could be cropped manually by editing the MediaBox.
PDF files conforming to older versions of the format can be done that way ... as long as you do not add or delete any characters! -- that will screw up the object offset table, and it's not certain that recovery will work. (If you have some other Box nearby, containing the same data, you may be able to remove it to get the extra character space: if I remember, all Boxes default to MediaBox if they aren't specified.)

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.
ath is offline   Reply With Quote
Old 08-14-2006, 01:09 PM   #11
ali
Addict
ali doesn't litterali doesn't litter
 
ali's Avatar
 
Posts: 302
Karma: 116
Join Date: May 2006
Device: Iliad, dude!
Quote:
Originally Posted by ath
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.
That explains the "bad xref table" errors I was getting. Xpdf complains "Error (0): PDF file is damaged - attempting to reconstruct xref table..." but displays pages correctly afterwards.

"Save a copy" in acroread doesn't fix it... Hmmmmmmmmmmmmmmmm Have to think about this.
ali is offline   Reply With Quote
Old 08-14-2006, 01:51 PM   #12
arivero
Guru
arivero knows what time it isarivero knows what time it isarivero knows what time it isarivero knows what time it isarivero knows what time it isarivero knows what time it isarivero knows what time it isarivero knows what time it isarivero knows what time it isarivero knows what time it isarivero knows what time it is
 
arivero's Avatar
 
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.
arivero is offline   Reply With Quote
Old 08-14-2006, 02:02 PM   #13
k2r
Zealot
k2r doesn't litterk2r doesn't litter
 
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
k2r is offline   Reply With Quote
Old 08-14-2006, 05:53 PM   #14
harryo
Enthusiast
harryo began at the beginning.
 
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
Quote:
Originally Posted by ElaHuguet
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.
Ah, yes. That could explain it. It may be the ones where I didn't need to crop top and bottom much that are showing more white space on the left and right than I'd expected.
harryo is offline   Reply With Quote
Old 08-14-2006, 05:58 PM   #15
harryo
Enthusiast
harryo began at the beginning.
 
Posts: 34
Karma: 10
Join Date: Aug 2006
Device: Palm Tungsten TX / Iliad
Quote:
Originally Posted by arivero
Also a pdfcrop utility exist in the TeX packages, but it generates files bigger.
That sounds like the perfect way to do it.

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.
harryo is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cropping Multiple Files SpyKiIIer PDF 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 PDF 4 01-16-2009 05:42 AM


All times are GMT -4. The time now is 09:45 AM.


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