Menu

#65 Bookmark iteration problem

0.1.2.1
closed-works-for-me
None
3
2015-03-09
2015-02-26
No

Hi,

I have a PDF file which has three bookmarks. Pdf clown returns only one bookmark when I iterate bookmarks.

When I looked the Bookmarks.cs's GetEnumerator method. it seems that first bookmark object must have /Next keyword but my pdf file has not.

I tried to fix that but I think that this is not the best solution.

I changed GetEnumerator method like this:

    IEnumerator<Bookmark> IEnumerable<Bookmark>.GetEnumerator(
      )
    {
        PdfDictionary firstBookmarkDictionary = BaseDataObject;

        PdfDirectObject tempBookmarkObject = null;
        PdfDirectObject bookmarkObject = null;

        do
        {
            tempBookmarkObject = firstBookmarkDictionary[PdfName.First];
            if (tempBookmarkObject != null)
            {
                bookmarkObject = tempBookmarkObject;
                firstBookmarkDictionary = (PdfDictionary)bookmarkObject.Resolve();
            }
        } while (tempBookmarkObject != null);

        if (bookmarkObject == null)
            yield break;

        do
        {
            yield return new Bookmark(bookmarkObject);

            bookmarkObject = ((PdfDictionary)bookmarkObject.Resolve())[PdfName.Next];
        } while (bookmarkObject != null);
    }
1 Attachments

Discussion

  • Stefano Chizzolini

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -8,7 +8,7 @@
    
     I changed GetEnumerator method like this:
    
    
    - IEnumerator<Bookmark> IEnumerable<Bookmark>.GetEnumerator(
    +        IEnumerator<Bookmark> IEnumerable<Bookmark>.GetEnumerator(
               )
             {
                 PdfDictionary firstBookmarkDictionary = BaseDataObject;
    
    • assigned_to: Stefano Chizzolini
     
  • Stefano Chizzolini

    Your bug is not confirmed -- I tried your attachment through BookmarksParsingSample but its output seems ok:

    Bookmark 'feff005200650070006f007200740031'
      Target: LocalDestination [ 5 0 R XYZ 0 810,709 0 ]
      Page 1 [ID: 5 0 R]
    Bookmark 'feff005000610072006100660031'
      Target: LocalDestination [ 5 0 R XYZ 17,008 725,669 0 ]
      Page 1 [ID: 5 0 R]
    Bookmark 'feff005000610072006100660032'
      Target: LocalDestination [ 5 0 R XYZ 17,008 697,323 0 ]
      Page 1 [ID: 5 0 R]
    Bookmark 'feff005000610072006100660033'
      Target: LocalDestination [ 5 0 R XYZ 17,008 668,976 0 ]
      Page 1 [ID: 5 0 R]
    
     
  • Stefano Chizzolini

    • status: open --> closed-works-for-me
     

Log in to post a comment.

MongoDB Logo MongoDB