#3 Getting annotations out of an existing PDF

closed-fixed
nobody
None
5
2014-10-10
2006-05-04
rdenne
No

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.

Thanks

Discussion

  • PDFsharp Team
    PDFsharp Team
    2006-05-10

    Logged In: YES
    user_id=1359308

    Should work with Beta 3 now. If you have still problems
    please send us the PDF file that causes the problem.

     
  • PDFsharp Team
    PDFsharp Team
    2006-05-10

    • status: open --> closed-fixed