You may call getImportedPage on the same reader more than once only if the pages doesn't ahave any annotation.
Paulo ----- Original Message ----- From: "Kevin Day" <[EMAIL PROTECTED]> To: "itext-questions-request@" <lists.sourceforg [email protected]> Sent: Saturday, October 11, 2008 12:35 AM Subject: [iText-questions] 'Could not find XObject named Xi1' error afterusing PdfCopy with PageStamp We are having a problem with PdfCopy (and PdfSmartCopy) generating PDFs that give the following error in Acrobat when navigating to any page except the first page: Could not find XObject named 'Xi1' The stamped content appears on the first page of the PDF only. Subsequent pages show the original content, but not the stamp content. We have traced the trigger to whether we re-instantiate the PdfReader used for the content source of the stamp for every single output page. If we re-use the PdfReader from page to page, we get the above error. If we create a new PdfReader for every page, we do not get the above error. Here is test code that will recreate the problem (if you change resetStampEachPage to true, the PDF generated behaves properly): public void mergeAndStampPdf(File[] in, File out, File stamp) throws Exception { Document document = new Document(); PdfCopy writer = new PdfSmartCopy(document, new FileOutputStream(out)); document.open(); boolean resetStampEachPage = false; int stampPageNum = 1; PdfReader stampReader = new PdfReader(stamp.getPath()); for (int inNum = 0; inNum < in.length; inNum++){ // create a reader for the input document PdfReader documentReader = new PdfReader(in[inNum].getPath()); for (int pageNum = 1; pageNum <= documentReader.getNumberOfPages(); pageNum++){ // import a page from the main file PdfImportedPage mainPage = writer.getImportedPage(documentReader, pageNum); // make a stamp from the page and get under content... PdfCopy.PageStamp pageStamp = writer.createPageStamp(mainPage); // import a page from a file with the stamp... if (resetStampEachPage) stampReader = new PdfReader(stamp.getPath()); PdfImportedPage stampPage = writer.getImportedPage(stampReader, stampPageNum++); // add the stamp template, update stamp, and add the page pageStamp.getOverContent().addTemplate(stampPage, 0, 0); pageStamp.alterContents(); writer.addPage(mainPage); if (stampPageNum > stampReader.getNumberOfPages()) stampPageNum = 1; } } writer.close(); document.close(); } It seems odd to me that it wouldn't be legal to call getImportedPage on the same reader more than once (after all, we are calling getImportedPage on the source file reader multiple times without issue). I noticed in the source for PdfCopy#createPageStamp() that it says that it modifies the Reader instance, but I'm assuming this refers to the reader associated with the page passed in to createPageStamp. Any ideas on what's going on here (or are we mis-using something)? Thanks! - K ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ 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 ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ 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
