Menu

Error opening secure PDF

Sybeus
2012-07-09
2023-08-23
  • Sybeus

    Sybeus - 2012-07-09

    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.

     
  • christeena

    christeena - 2023-08-17

    why certain pdf's are not able to read by pdfsharp library..?

     
  • PDFsharp Team

    PDFsharp Team - 2023-08-23

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.