Discussion:
[iText-questions] why does portrait page changes to landscape page automatically after inserting pdf using iText?
r***@gmail.com
2016-04-11 10:08:40 UTC
Permalink
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



--
View this message in context: http://itext.2136553.n4.nabble.com/why-does-portrait-page-changes-to-landscape-page-automatically-after-inserting-pdf-using-iText-tp4661023.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/
gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net
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
ramas
2016-04-18 15:44:39 UTC
Permalink
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();



--
View this message in context: http://itext.2136553.n4.nabble.com/why-does-portrait-page-changes-to-landscape-page-automatically-after-inserting-pdf-using-iText-tp4661023p4661026.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net
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
Loading...