Error opening secure PDF
PDFsharp is a .NET library for creating and modifying PDF documents.
Brought to you by:
pdfsharp,
stefan_lange
When opening a secure PDF document and pValue is retrieved within PdfSharp.Pdf.Security.PdfStandardSecurityHandler.ValidatePassword(string inputPassword), it uses PdfSharp.Pdf.PdfDictionary.DictonaryElements.GetInteger(string key, bool create). If PdfDictionary contains an unsigned integer for the value of /P, then GetInteger() throws an InvalidCastException which bubbles all the way up to the Open command, thus preventing opening of some secure PDF documents.
To fix this, I suggest including the following two lines in PdfSharp.Pdf.PdfDictionary.DictonaryElements.GetInteger(string key, bool create) just before it throws the InvalidCastException:
if (obj is PdfUInteger)
return (int)((PdfUInteger)obj).Value;
It's worked so far for me. I haven't done extensive testing on whether this would greatly impact other methods using GetInteger.
why certain pdf's are not able to read by pdfsharp library..?
Hello everybody!
Please use our PDFsharp support forum to ask questions:
http://forum.pdfsharp.net/
It's more convenient for us to have all questions in one place.