PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 6:49 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Mar 23, 2010 6:28 pm 
Offline

Joined: Sun Mar 02, 2008 3:17 pm
Posts: 6
Hi all,

I am trying to walk the annotations list per page in an existing pdf. I have tried various permutations of the following foreach loops in C#

Code:
                foreach (PdfPage page in pdf.Pages)
                {
                    PdfAnnotations annots = page.Annotations;
                    PdfArray annArray = annots;
                    foreach (var ann in annArray)
                    {
                    }
               }



Every variation recives an invalid cast error

Unable to cast object of type 'AnnotationsIterator' to type 'System.Collections.Generic.IEnumerator`1[PdfSharp.Pdf.PdfItem]'

I can get around this by walking the document internal looking for dictionaries that are /Annot /Link. but that looses page affinity.

any thoughts on how to get around this.

Bille


Top
 Profile  
Reply with quote  
PostPosted: Thu May 27, 2010 11:53 am 
Offline

Joined: Thu Oct 16, 2008 1:54 pm
Posts: 14
This is a bug introduced in v1.31:
  • In v1.2, the PdfAnnotations class implemented IEnumerable, and the nested AnnotationsIterator class implemented IEnumerator;
  • In v1.31, PdfAnnotations implements IEnumerable<PdfItem>, and the AnnotationsIterator implements IEnumerator<PdfAnnotation>;
  • The v1.31 GetEnumerator method tries to cast the AnnontationsIterator instance to an IEnumerator<PdfItem>, which would only work in .NET 4.0;

Unfortunately, short of switching to v1.2, the only solution is to iterate by hand:
Code:
for (int index = 0; index < page.Annotations.Count; index++)
{
    var ann = page.Annotations[index];
    ...
}


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 43 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group