PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Aug 14, 2018 7:01 am

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: Wed Mar 21, 2012 1:56 pm 

Joined: Wed Mar 21, 2012 1:35 pm
Posts: 2

I'm very happy using PdfSharp, but just only today we had a problem using it with a large file (32mo)
While calling Save() the exception "An item with the same key has already been added" is thrown.

The PDF is openned with :
_pdfDocument = PdfSharpPdf.IO.PdfReader.Open( IO.File.OpenRead(filePath), PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify)

The exception is happening in PdfReferenceTable.cs:257 of the last release "1.32.2608.0"


Can I solve the probleme without having anything messed up in the PDFs with a IF before testing if the "this.objectTable" ContainsKey(iref.ObjectID) ? If it contains then nothing is added

What do you think about this solution ?

Thank you for helping

capture error PdfSharp.png
capture error PdfSharp.png [ 23.32 KiB | Viewed 3656 times ]
Reply with quote  
PostPosted: Wed Mar 21, 2012 3:15 pm 

Joined: Wed Mar 21, 2012 1:35 pm
Posts: 2
Hello again,

The code that produce this error is the following:
        Using graf = Drawing.XGraphics.FromPdfPage(page)

            Dim pen As Drawing.XPen = _penConfig
            For Each stick In sequence

                graf.DrawLine(pen, positionX, positionY, positionX, positionY + PipeHeight)
                positionX += PipeWidth + PipeSpace
        End Using

We use a XGraphics object to draw bars, when commenting this part they are no error in the Saving of the Pdf.

When I keep this part, the exception is thrown and when comparing the 2 objects (one already existing in the dictionary and the one causing the exception. "iref" is from the loop iteration of "irefs", "o" is the PdfReference already existing in the directionary) we can see borth have the same ObjectID but different uid. ref attached image.

How is this possible as we dispose the XGraphics reference ?

Thanks for helping :-)

File comment: Code edited for testing the exception
capture error PdfSharp3.png
capture error PdfSharp3.png [ 20.67 KiB | Viewed 3655 times ]
capture error PdfSharp2.png
capture error PdfSharp2.png [ 46.01 KiB | Viewed 3655 times ]
Reply with quote  
PostPosted: Mon Mar 26, 2012 7:36 am 
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2846
Location: Cologne, Germany

Boss says this probably is a bug in PDFsharp. Please provide us with your PDF file and your code so we can replicate the problem here using a debugger.
E-mail address sent via PM.

Thomas Hoevel
PDFsharp Team

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 2 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