I have a file that when trying to copy pages it gives a KeyNotFoundException error.
Error happens at line 5 on following code:
Code:
1 PdfDocument PDFDoc = PdfReader.Open(filename, PdfDocumentOpenMode.Import);
2 PdfDocument document = new PdfSharp.Pdf.PdfDocument();
3 for (int Pg = 0; Pg < PDFDoc.Pages.Count; Pg++)
4 {
5 document.AddPage(PDFDoc.Pages[Pg]);
6 }
I can forward the PDF in a email if needed, appreciate the help.
Detail on error:
Unhandled Exception: System.Collections.Generic.KeyNotFoundException: The given
key was not present in the dictionary.
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at PdfSharp.Pdf.Advanced.PdfImportedObjectTable.get_Item(PdfObjectID external
ID)
at PdfSharp.Pdf.PdfObject.FixUpObject(PdfImportedObjectTable iot, PdfDocument
owner, PdfObject value)
at PdfSharp.Pdf.PdfObject.FixUpObject(PdfImportedObjectTable iot, PdfDocument
owner, PdfObject value)
at PdfSharp.Pdf.PdfObject.ImportClosure(PdfImportedObjectTable importedObject
Table, PdfDocument owner, PdfObject externalObject)
at PdfSharp.Pdf.PdfPages.CloneElement(PdfPage page, PdfPage importPage, Strin
g key, Boolean deepcopy)
at PdfSharp.Pdf.PdfPages.ImportExternalPage(PdfPage importPage)
at PdfSharp.Pdf.PdfPages.Insert(Int32 index, PdfPage page)
at PdfSharp.Pdf.PdfDocument.AddPage(PdfPage page)
at Watermark.Program.Main()