PDFsharp & MigraDoc Foundation

pdf encryption assertion failure
Page 1 of 1

Author:  berrywhite [ Fri Aug 05, 2016 6:47 pm ]
Post subject:  pdf encryption assertion failure

I encountered an assertion failure when I tried to encrypt some specific pdf file (sorry it's 500KiB with only one page and cannot be uploaded)

and I am using the pdf sharp source code (PDFsharp-1_50-beta3b.zip) to build my own PdfSharp.dll,

I noticed that this pdf triggers the following code in PdfDocument.cs

// HACK: Remove XRefTrailer
if (_trailer is PdfCrossReferenceStream) ----------------> condition got met
_trailer = new PdfTrailer((PdfCrossReferenceStream)_trailer);

Although I have no idea why we need this hack, it seems the failure can be fixed by adding the following codes:

iref = trailer.Elements.GetReference(Keys.Encrypt);
if (iref != null)
Elements.SetReference(Keys.Encrypt, trailer.Elements.GetReference(Keys.Encrypt));
in the function "public PdfTrailer(PdfCrossReferenceStream trailer)" in PdfTrailer.cs

Please help to confirm, thx

Author:  TH-Soft [ Fri Aug 05, 2016 7:35 pm ]
Post subject:  Re: pdf encryption assertion failure


My proposed fix for this issue can be found here:

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group