Getting annotations out of an existing PDF
PDFsharp is a .NET library for creating and modifying PDF documents.
Brought to you by:
pdfsharp,
stefan_lange
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
Should work with beta 3. If not, send us the PDF file.