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.

Paulo

On Thu, May 10, 2012 at 1:00 AM,  <[email protected]> wrote:
> Goals:
>
> (1) To obtain a “copy” of an existing PDF (including interactive features)
>
> (2) The “copy” must be on a slightly larger page, to accommodate goal 3.
>
> (3) Place text in the “border” created from placing the original page on the
> slightly larger page.
>
>
>
> Background:
>
> (1) I have read and re-read iText in Action several/many times (both
> editions) and simply confuse myself more and more each time I read it.
> However, I think I am beginning to have a better understanding.
>
> (2) I have actually written code that does all of the above with the slight
> exception that interactive features are lost.
>
> (3) Using iText 5.0.2
>
>
>
> Question:
>
> Am I using the best approach as detailed in my current algorithm that
> follows?
>
> 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.
>
> 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?
>
> Or is that only when using PdfCopy/SmartCopy?
>
>
>
> Current Algorithm:
>
> Goal #3 is another step (not included here) and seems to working just fine
> (though the answer to my question may affect this).
>
> Goals #1 and #2 are combined into a single method which is where I am losing
> interactive features:
>
>
>
>     private File enlargeDocument(String src, int stampType, boolean
> docDelState) throws IOException, DocumentException {
>
>
>
>         final PdfReader rdr = createPdfReader(src);
>
>         int count = rdr.getNumberOfPages();
>
>
>
>         final File tmpDstFile = createTempPDFFile();
>
>         final Document document = new Document();
>
>         final PdfWriter writer = PdfWriter.getInstance(document, new
> FileOutputStream(tmpDstFile));
>
>
>
>         document.open();
>
>
>
>         final PdfContentByte cb = writer.getDirectContent();
>
>         for ( int i = 1 ; i <= count ; i++ ) {
>
>
>
>             final float cropSize = calcStampCropSize(rdr, i, stampType);
>
>
>
>             final PdfImportedPage page = writer.getImportedPage(rdr, i);
>
>             final int rotation = rdr.getPageRotation(i);
>
>             logger.debug("Rotation of page " + i + " is: " + rotation);
>
>
>
>             final float width = page.getBoundingBox().getRight() +
> ((stampType == PRESTAMP) ? 0 : cropSize);
>
>             final float height = page.getBoundingBox().getTop() +
> ((stampType == PRESTAMP) ? cropSize : 0);
>
>             final PdfRectangle newRect = new PdfRectangle(width, height,
> rotation);
>
>
>
>             document.setPageSize(newRect.getRectangle());
>
>             document.newPage();
>
>
>
>             if (stampType == PRESTAMP) {
>
>                     cb.addTemplate(page, 0, cropSize);
>
>             } else { // stampType == POSTSTAMP
>
>                     cb.addTemplate(page, cropSize, 0);
>
>             }
>
>         }
>
>
>
>         document.close();
>
>
>
>         return tmpDstFile;
>
>     }
>
>
>
>
> ------------------------------------------------------------------------------
> 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

------------------------------------------------------------------------------
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

Reply via email to