why does portrait page changes to landscape page automatically after inserting pdf using iText?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

why does portrait page changes to landscape page automatically after inserting pdf using iText?

ramas
Hi All,

Am using "itext-5.5.8", trying to insert two pages of portrait pdf into a main pdf document, code works perfect but after inserting portrait pages automatically changes to landscape pages, don't know why?

*****************************************************************

        try {
        PdfReader firstPdf = new PdfReader(mainFileWithPath); //main doc
        PdfReader secondPdf =new PdfReader(addFileNameWithPath); // inserting pages

        PdfStamper stamp = new PdfStamper(firstPdf, new FileOutputStream(outputPDFFile));

            int totalNumOfPagesToInsert = secondPdf.getNumberOfPages();
            int i =1;
            while (i<=totalNumOfPagesToInsert) {
                // Get a page(s) from secondPdf with the given pageNo
                PdfImportedPage page  = stamp.getImportedPage(secondPdf,i);

                // insert new page in to the newly created pdf at specified page number.
                stamp.insertPage(INSERT_AT_PAGE_NO + (i-1), secondPdf.getPageSize(i));

                // copy the content of the page copied from secondPdf.
                stamp.getUnderContent(INSERT_AT_PAGE_NO + (i-1)).addTemplate(page, 0, 0);

                i++;
            }

            //close the new created pdf.
            stamp.close();

****************************************************************

Please give me directions to fix this! Thanks
Reply | Threaded
Open this post in threaded view
|

Re: why does portrait page changes to landscape page automatically after inserting pdf using iText?

ramas
Answer is ....

try {

            PdfReader firstPdf = new PdfReader(mainFileWithPath);
            PdfReader secondPdf =new PdfReader(addFileNameWithPath);

            // create new pdf with the content from firstPdf
            PdfStamper stamp = new PdfStamper(firstPdf, new FileOutputStream(outputPDFFile));
            stamp.setRotateContents(false);

            int totalNumOfPagesToInsert = secondPdf.getNumberOfPages();
            int i =1;
            while (i<=totalNumOfPagesToInsert) {
                // Get a single page from secondPdf with the given pageNo
                PdfImportedPage page  = stamp.getImportedPage(secondPdf,i); //Actual working code

                // insert new page in to the newly created pdf at specified page number.
                // choose page size bas
                stamp.insertPage(INSERT_AT_PAGE_NO + (i-1), secondPdf.getPageSizeWithRotation(i)); //Actual working code

                // copy the content of the page copied from secondPdf.
                stamp.getUnderContent(INSERT_AT_PAGE_NO + (i-1)).addTemplate(page, 0, 0); //Actual working code

                i++;
            }

            //close the new created pdf.
            stamp.close();