Hi Experts,
    I have a requirement to create n copies of the same pdf document in new
pdf file.I  am using iText2.1.7. Actual pdf is in landscape format.But the
merged out is not coming properly.
I have attached the sample & output document.

Please my code  below.
public ByteArrayOutputStream doCopy(ByteArrayOutputStream bout,int
noOfCopies)
    throws DocumentException, IOException {
        ByteArrayOutputStream combinedOut = new ByteArrayOutputStream();

        Document document = new Document((new PdfReader(new
ByteArrayInputStream(bout.toByteArray()))).getPageSizeWithRotation(1));

            PdfWriter writer = PdfWriter.getInstance(document, combinedOut);
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            PdfReader reader ;
            int icount=0;
            for (int j=0;j<noOfCopies;j++)
            {

               reader  = new PdfReader(new
ByteArrayInputStream(bout.toByteArray()));



               ;
                for (int i = 1; i <= reader.getNumberOfPages(); i++) {
                    document.newPage();
                    //import the page from source pdf
                    PdfImportedPage page = writer.getImportedPage(reader,
i);

                    //add the page to the destination pdf
                    cb.addTemplate(page, 0, 0);
                }
            }

            combinedOut.flush();
            document.close();


        return combinedOut;
    }

Kindly help me to  fix this issue.

-- 
by
skumar

Attachment: output.pdf
Description: Adobe PDF document

Attachment: sample.pdf
Description: Adobe PDF document

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
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