So the psuedocode would be:

For every object on pdfpage
{
        object.get bounding box (probably using PDFRectangle)
        if the area of the current object's bounding box is greater than
the area of the largest one we have seen so far
        set the largest area to the area this objects bounding box
}

Get the page box,

Margin = rectangular Area of page box - rectangular area of largest
bounding box

If you want to crop, in the case of an image, you would select a
rectangle with the rectangular area of the largest bounding box on the
page

Does someone have some real code, or at least the classes/methods to use
for 

1. iterating through all page objects 
2. getting bounding box of objects
3. Getting area of pagebox.

Or a link to a message someone who has posted this code before :-x

Richard Braman
mailto:[EMAIL PROTECTED]
561.748.4002 (voice) 

http://www.taxcodesoftware.org
Free Open Source Tax Software



-----Original Message-----
From: Leonard Rosenthol [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 23, 2006 6:47 AM
To: [EMAIL PROTECTED]
Subject: RE: [iText-questions] PdfImportPage Margins


At 01:25 AM 2/23/2006, Richard Braman wrote:
>I have a similar question about that to:  When I extracted the IRS form

>pages in my PDF using JPEDAL, thye had whitespace "margins" around the 
>form,  I am sure you know of this as an offset, or some other PDF 
>slang, but I think that's what Jordan was referring to as a margin.  I 
>wanted to crop this space, and I know it can be done.  Basically you 
>are looking for a rectangle that doesn't contain the margin.  Anyone 
>know how to do that?

         A "margin" is simply whitespace containing no content on 
each edge of the page.   The only way to determine this is to get the 
bounding box of every object on the page and figure out the largest 
area that it covers.  Then the difference between that box and the 
page box is the "margin".


LDR

------------------------------------------------------------------------
---
Leonard Rosenthol
<mailto:[EMAIL PROTECTED]>
Chief Technical Officer                      <http://www.pdfsages.com>
PDF Sages, Inc.                              215-938-7080 (voice)
                                              215-938-0880 (fax)



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to