Hi,

I am creating several new PDF documents based on selected pages from a master document using the following code:

    private static byte[] getPDF(final int startPage, final int endPage, final PdfReader reader) {
        Document doc = new Document(reader.getPageSize(1));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            PdfWriter writer = PdfWriter.getInstance(doc, baos);

            doc.open();
            PdfContentByte cb = writer.getDirectContent();
            PdfImportedPage p;

            for(int i = startPage; i <= endPage; i++) {
                doc.newPage();
                p = writer.getImportedPage(reader, i);
                cb.addTemplate(p, 0, 0);
            }
            //fos.flush();
            doc.close();
            //fos.close();
            baos.flush();
            baos.close();
        } catch(IOException ex) {
            throw new IllegalStateException("Error genereating new split PDF. " + ex.getMessage());
        } catch(DocumentException ex) {
            throw new IllegalStateException("Error genereating new split PDF. " + ex.getMessage());
        }
        return baos.toByteArray();
    }

For some master PDFs, the new smaller PDFs generated are fine - however for some PDFs, it appears that the tables on the document are getting stretched, resulting in the top of the document appearing to be cropped.

Has anyone noticed this before and does anyone have a solution, and also is there a better way of doing the above which guarantees I get a one to one copy from the main PDF to the smaller PDFs?

Many thanks,

Matthew Hawkins



Email has been scanned for viruses
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to