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
OUT.pdf
Description: Adobe PDF document
IN.pdf
Description: Adobe PDF document