Given a page from a pdf document, I would like to be able to find the margin for the text, using objetive-C.
I realise there are already many questions relating to CGPDF...
, but I have not been able to find anything useful. I have also had a look at the PDF specification doc. I am sure it must be in there somewhere, but I have not been able to find it yet.
I create a Word document which has a left and right margin of 2.5cm each. I then print to pdf. Taking this pdf, is there some way to figure out the width of the text (ie, the left and right page margin)?
In case I am barking up the wrong tree, the reason I am asking this question is to be able to zoom like iBooks zooms. If you double tap on iBooks, it will take zoom you to the width of the main body. This is the same in the Mac's Preview application (pressing "Zoom to Fit").
I first thought that maybe PDF Boxes
(CGPDFPage
) like kCGPDFBleedBox
might be able to help, but it does not look like it will help in my case.
I am only concerned with the body text of the page. Images etc, that might be outside this do not bother me.
Fast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints?
You can render the PDF page as a bitmap, detect its pixel status and get the white margins. Take a look at this excellent implementation from Skim: http://skim-app.svn.sourceforge.net/viewvc/skim-app/trunk/NSBitmapImageRep_SKExtensions.m?revision=7036&content-type=text%2Fplain