First, thank you for the good explanation (and the bonus of how quick it came).
Clarification:
(1) I suppose there is a language/terminology barrier here and I am trying
carefully to find the right words so let me try again in case this might prompt
different advice:
I am not wanting to scale/enlarge the content of the existing PDF (nor am I
currently doing so). The goal is to place the existing content (completely
unmodified) on a slightly larger page; this will result in extra "white space"
for which to place more content. The reason for this approach (instead of
simply using PdfStamper as explained in the many iText in Action samples) is
that the source PDF is not guaranteed to contain enough "white space"/margins
so that the "stamp" does not overlap existing content. I hope that makes sense.
(2) Having explained the above, I think I need to research Paulo's advice of:
If you only want to add margins just change the mediabox and use PdfStamper to
output the PDF. You can also add text or any other content with PdfStamper.
Thanks again. I will repost if I put all this together in a way that changes
my algorithm.
From: 1T3XT BVBA [mailto:[email protected]]
Sent: Thursday, May 10, 2012 1:46 AM
To: [email protected]
Subject: Re: [iText-questions] Copy/Enlarge a PDF
On 10/05/2012 2:00, [email protected]<mailto:[email protected]>
wrote:
It would seem that I should probably be using PdfStamper somehow (even though I
think that will result in a different approach to increasing the page size.
That's possible, but you'll have to do more Math.
However, unless I have mis-read this many times now, I thought the whole idea to
writer.getImportedPage()
was to retain interactive features by letting the writer use the reader?
No, as explained in table 6.1, using PdfWriter + PdfImportedPage throws away
all interactive features.
Or is that only when using PdfCopy/SmartCopy?
Yes, that's what table 6.2 tells you.
You have read "iText in Action", but you're missing one important concept.
In PDF, you have content and you have annotations.
You'll find the content of a page as a (series of) stream(s) in the page
dictionary. There's the /Contents entry, and also the XObjects under /Resources.
You'll find the annotations as a series of dictionaries in the page dictionary.
Look for the /Annots entry.
Currently, you are only copying (and scaling) the content.
You are ignoring all the interactive features (links, annotations, field
widgets,...).
I have never understood why people want to enlarge a PDF (PDFs are usually
vector based and size doesn't really matter), but suppose that you would like
to scale the document, then:
- you have to change the CTM used to draw the content (you already found out
how to do that; iText is a great help because there are plenty of convenience
method that do the math for you, unless you want to use PdfStamper),
- recalculate all the rectangle values of the annotations (iText won't help you
here; you'll need to do all the Math yourself).
Knowing this, please open your PDF using iText RUPS, and have a look inside.
You'll find annotations with entries named /Rect (the rectangle defining the
position of the interactive feature) looking like this [100 100 300 120]:
that's a rectangle with a lower left corner x = 100, y = 100 and an upper right
corner x = 300, y = 120. Note that Y-coordinate of the lower corner has a
smaller value than the Y-coordinate of the upper corner.
If you want to enlarge a PDF document INCLUDING all interactive features, you
should copy the content (you're already doing that), but ALSO the annotations
(so far you've ignored them). When you copy the annotations, you need to change
the coordinates of the annotations using Algebra (matrix multiplication).
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php