Hi,
I am new to iText and I am currently working on a small tool which converts
the PDF files with different sizes (A4, LETTER) to A4.
The problem is that I can reszie all the pages in a PDF file but the page
rotation is lost; means if source document is type LETTER and LANDSCAPE, the
target document convert the size to A4 but orientation is PORTRAIT.
Any help in this regard is much appriciated.
Thanks
-Ravi M
Source (createPDF method)
public void createPDF(String inputFile, String outputFile) {
Document document = new Document(PageSize.A4);
try {
PdfReader reader = new PdfReader(inputFile);
int noOfPages = reader.getNumberOfPages();
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(outputFile));
document.open();
PdfContentByte cb = writer.getDirectContentUnder();//.getDirectContent();
for (int i = 1; i<= noOfPages; i++) {
if (i != noOfPages) {
if (determinePageSize(reader.getPageSize(i))) {
System.out.println("Page size is landscape");
document.setPageSize(reader.getPageSize(i).rotate());
}
else {
System.out.println("Page size is portrait");
document.setPageSize(reader.getPageSize(i));
}
}
else {
document.setPageSize(PageSize.A4);
}
document.newPage();
PdfImportedPage page = writer.getImportedPage(reader, i);
System.out.println("for page "+ i + " height ... "+ page.getHeight()
+" width ... " + page.getWidth());
cb.addTemplate(page, 0f, 0f);
}
} catch (Exception e) {
e.printStackTrace();
}
document.close();
}
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
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