Menu

Getting annotations out of an existing PDF

rdenne
2006-04-27
2013-04-23
  • rdenne

    rdenne - 2006-04-27

    I was trying to use PdfSharp to retrieve comments from a PDF and save as XML.  But I find that I get exceptions thrown if I try this code:

    PdfDocument doc = PdfReader.Open(filename,
      PdfDocumentOpenMode.ReadOnly);
    for (int pgCt = 0; pgCt < doc.PageCount; pgCt++)
    {
      PdfPage pg = doc.Pages[pgCt];
     
      for (int annCt = 0; annCt < pg.Annotations.Count;
        annCt++)
      {
        PdfAnnotation ann = pg.Annotations[annCt];
        SWF.MessageBox.Show(ann.Contents);
      }
    }

    I get a System.InvalidCastException thrown in PdfDictionary at line 654.  The problem is that the value is a PdfArray and cannot be casted to a PdfDictionary ref.

    I have looked at the sample Annotations class, but that works fine since it just adds a new PdfPage and then adds annotations to that new page.

    Any help?

    Thanks

     
    • PDFsharp Team

      PDFsharp Team - 2006-05-18

      Should work with beta 3. If not, send us the PDF file.

       

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.