PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 10:54 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Jan 21, 2010 7:18 pm 
Offline

Joined: Fri Jan 15, 2010 8:58 pm
Posts: 2
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()


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 22, 2010 6:13 pm 
Offline

Joined: Fri Jan 15, 2010 8:58 pm
Posts: 2
Never mind, I also encountered the iref issue with the PDFs I'm trying to watermark so after reading this is not supported I had no choice but to change the library to iTextSharp, which by the way works great, it's very stable and I've now completed my project.

If you are still interested in the PDF file I can still email it.


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 22, 2016 8:22 am 
Offline

Joined: Tue Nov 22, 2016 4:56 am
Posts: 1
Can you send the sample file with fix. Because I am also getting same problem. So I have tried with iTextSharp to read PDF file like as below,

Code:
Dim oReader As New iTextSharp.text.pdf.PdfReader(fileStream)
Dim pdfdocument As New iTextSharp.text.Document(oReader.GetPageSizeWithRotation(1))
Dim n As Integer = oReader.NumberOfPages
Dim outputStream As New MemoryStream
Dim pdfwriter As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfdocument, outputStream)
pdfwriter.SetPdfVersion(iTextSharp.text.pdf.PdfWriter.PDF_VERSION_1_4)

pdfdocument.Open()
Dim cb As iTextSharp.text.pdf.PdfContentByte = pdfwriter.DirectContent
Dim page As iTextSharp.text.pdf.PdfImportedPage

Dim rotation As Integer

Dim i As Integer = 0
While i < n
i += 1
pdfdocument.SetPageSize(oReader.GetPageSizeWithRotation(i))
pdfdocument.NewPage()
page = pdfwriter.GetImportedPage(oReader, i)
rotation = oReader.GetPageRotation(i)
If rotation = 90 OrElse rotation = 270 Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, _
oReader.GetPageSizeWithRotation(i).Height)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, _
0)
End If
End While

'---- Keep the stream open!
pdfwriter.CloseStream = False

'----- we close the document
pdfdocument.Close()

return  PdfSharp.Pdf.IO.PdfReader.Open(outputStream, openmode)


But links are disabled. Please let me know how to handle this issue.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 56 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group