PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Dec 16, 2017 7:25 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Nov 17, 2017 10:34 pm 
Offline

Joined: Fri Nov 17, 2017 10:20 pm
Posts: 2
Hi all,

How would one go about creating a page label for pages of a PDF.

Also, i cant seem to find anything on how to retrieve a specific page by a name from a book mark, or page label.

i was able to create bookmarks using the outline property and add method.

when i later open this PDF again for more editing, how would i find a specific page using a name from the bookmark?


Thanks.


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 21, 2017 2:18 pm 
Offline

Joined: Tue Sep 30, 2014 12:29 pm
Posts: 17
That should be easy, just follow the references ! ;-)
If you open a Pdf with a text-editor, you should be able to see, what i mean.
The outlines are defined in the document catalog: (object numbers will probably differ)
Code:
2 0 obj
<<
/Type/Catalog
/Pages 3 0 R
/Outlines 13 0 R

The "/Outlines" Entry is a reference to the Outlines-Dictionary:
Code:
13 0 obj
<<
/First 14 0 R
/Last 83 0 R

The "/First" entry references the first outline:
Code:
14 0 obj
<<
/Title(Page1)
/Parent 13 0 R
/Dest[4 0 R /XYZ null null 0]
/Next 28 0 R
>>

The "/Title" entry contains the name of the bookmark.
The "/Next" entry contains a reference to the next bookmark.
The "Dest" entry contains an array; the first element is a reference to the page.
Note, that the "/Next" entry will be missing if you reached the last bookmark.

Now, what i would do to find a page by a bookmark's name: (in pseudocode)
Code:
var outlinesDict = Catalog.GetDictionary("/Outlines");
if (outlinesDict != null)
{
   var outline = outlinesDict.GetDictionary("/First");
   while (outline != null)
   {
      var title = outline.GetString("/Title");
      if (title == "title_i_search_for")      // bookmark we're looking for ?
      {
         var destArray = outline.GetArray("/Dest");
         var pageRef = destArray.GetReference(0);   // stored at index zero
         for (var i = 0; i < document.NumPages; i++)
            if (document.Pages[i].ObjectNumber == pageRef.ObjectNumber)
               // Page found ! return page or whatever
      }
      // not the right bookmark, check next one
      outline = outline.GetDictionary("/Next");
   }
}

You should probably add more error-checking (i.e. check, whether destArray and pageRef are valid).


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 21, 2017 3:01 pm 
Offline

Joined: Fri Nov 17, 2017 10:20 pm
Posts: 2
Thanks for the help!

First time working with PDF's.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 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:  
Powered by phpBB® Forum Software © phpBB Group