Hi, I am using PDF Copy to create a copy of the existing PDF document that has annotations (links I need), bookmarks etc. Everything works great for smaller documents, but for larger ones when closing the Document I get the Error like the following:
Error Message: " The page 569 was requested but the document has only 568 pages." Stack Trace: " at iTextSharp.text.pdf.PdfWriter.Close() at iTextSharp.text.pdf.PdfCopy.Close() at iTextSharp.text.pdf.PdfDocument.Close() at iTextSharp.text.Document.Close() at iTextInAction.CopyPdf.CopyPdfWithAllResources() in D:\Projects\iTextInAction\Ch7\CopyPdf.cs:line 289" What I have discovered also is that if I remove line : cb.LocalDestination("test local destination" + i, new PdfDestination(PdfDestination.XYZ, 10, 11, 10)); everything works great, even for the larger documents. Can you advise me please, if I am doing anything wrong, below is my sample od the code Thanks, Vfeki Code: PdfReader reader = new PdfReader(@"pdfFiles\File1.pdf"); IList<Dictionary<string, Object>> list = SimpleBookmark.GetBookmark(reader); Dictionary<string, string> bookmarks = SimpleNamedDestination.GetNamedDestination(reader, false); int n = reader.NumberOfPages; Document document = new Document(reader.GetPageSizeWithRotation(1)); PdfCopy writer = new PdfCopy(document, new FileStream(@"pdfFiles\CopiedFile1.pdf", FileMode.CreateNew)); document.Open(); PdfContentByte cb = writer.DirectContent; for (int i = 1; i <= n; i++) { PdfImportedPage page1 = writer.GetImportedPage(reader, i); cb.AddTemplate(page1, 1, 1); cb.LocalDestination("test local destination" + i, new PdfDestination(PdfDestination.XYZ, 10, 11, 10)); writer.AddPage(page1); } PRAcroForm form1 = reader.AcroForm; if (form1 != null) { writer.CopyAcroForm(reader); } writer.Outlines = list; document.Close(); - where document.Close() throws the error above. I am using last iTextSharp library 5.1.2.0, and with previous one it did not work also. Am I doing anything wrong? Thanks in advance, Vfeki -- View this message in context: http://itext-general.2136553.n4.nabble.com/PdfWriter-throws-Exception-for-Page-Number-when-creating-larger-pdf-files-tp3882518p3882518.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 _______________________________________________ iText-questions mailing list iText-questions@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