Thursday, 15 July 2010

java - Combining pdfs with itext - landscape pages rendered as portrait -



java - Combining pdfs with itext - landscape pages rendered as portrait -

i'm maintaining legacy application uses itext combine multiple landscape , portrait pdfs. process working fine when combining pdfs produced same application, other pdfs renders landscape portait , cuts off content.

question: there properties in construction of pdf can cause such difference in rendering?

thanks!

the behavior you're describing occurs if follow bad examples. doesn't occur when follow the official documentation.

although didn't provide source code, i'm pretty sure utilize pdfwriter instance , add together existing pages direct content of instance using addtemplate() method. (as have pointed out many times people don't read documentation) wrong.

you need replace merging process , utilize pdfcopy or pdfsmartcopy concatenate pdf documents. take @ mergeforms (merging forms) , fillflattenmerge2 (introducing pdfsmartcopy resulting file size remains low) examples inspiration. if application old, may not find adddocument() method.

in case, need utilize old examples, such concatenate example:

document document = new document(); pdfcopy re-create = new pdfcopy(document, new fileoutputstream(result)); document.open(); pdfreader reader; int n; (int = 0; < files.length; i++) { reader = new pdfreader(files[i]); n = reader.getnumberofpages(); (int page = 0; page < n; ) { copy.addpage(copy.getimportedpage(reader, ++page)); } copy.freereader(reader); reader.close(); } document.close();

java itext

No comments:

Post a Comment