You got the point.
I need to crop the page using the margin values, but it seems that iText can't do this.
Do you know any 3rd party sftw that do this?
Thank again


Paulo Soares wrote:

Let's see if I understand your requirement.

1 - you want to find out the margin size base on the page content

2 - you want to crop the page

iText can't do 1.
To do 2:

PdfReader reader = new PdfReader(...);
PdfDictionary page = reader.getPageN(1);
page.put(PdfName.CROPBOX, new PdfArray(new float[]{10, 20, 30, 40}));
//the visible page
PdfStamper stp = new PdfStamper(reader, ...);
stp.close();

Best Regards,
Paulo Soares



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andrea Baccin
Sent: Tuesday, September 21, 2004 9:47 AM
To: [EMAIL PROTECTED]
Subject: Re: [iText-questions] PDF Cropping


Leonard Rosenthol wrote:



At 11:47 AM 9/20/2004, Andrea Baccin wrote:



I have the needing of modify existing pdf files: I need to

delete all


white space in left and upper margin.


Do you just need to visually remove that area from

display, or

actually change the physical PDF data to eliminate it?

PDF supports a "crop box" which effects the visual display, but doesn't actually remove anything from the PDF. That

can easily be

set with PdfStamper. To do the latter would be a LOT of work and require you to understand the internals of PDF - OR use a 3rd party product that can do it for you.



I need only to visually remove that area from display and print. This
can be easy done with the following code (I use iText Net):

Dim Reader As New PdfReader("IN.pdf")
Dim n As Integer = Reader.getNumberOfPages()
Dim psize As Rectangle = Reader.getPageSize(1)
Dim Document As New Document(psize, 1, 0, 1, 0)
Dim Writer As PdfWriter = PdfWriter.getInstance(Document, New
FileOutputStream("OUT.pdf"))
Document.open()
Dim cb As PdfContentByte = Writer.getDirectContent()
Document.newPage()
Dim page1 As PdfImportedPage = Writer.getImportedPage(Reader, 1)
page1.moveTo(0, 0)
cb.addTemplate(page1, 1.0F, 0, 0, 1.0F, -15, 85)
Document.close()


With the "addTemplate" I just set the x and y coordinates where I want
to paste the imported page. The main problem is that Y value must change
in function of the INput PDF. I've tried to use "getCropBox" but always
return the PageSize.
I've looked at PDFStamper API in
http://itext.sourceforge.net/docs/com/lowagie/text/pdf/PdfStamper.html
but I cannt find anything useful.
I've attached IN.pdf and OUT.pdf in case you want take a look at it.
Thanks a lot
Andrea




-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to