PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Create page labels and get page page by name. https://forum.pdfsharp.net/viewtopic.php?f=2&t=3693 |
Page 1 of 1 |
Author: | Goertz [ Fri Nov 17, 2017 10:34 pm ] |
Post subject: | Create page labels and get page page by name. |
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. |
Author: | (void) [ Tue Nov 21, 2017 2:18 pm ] |
Post subject: | Re: Create page labels and get page page by name. |
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). |
Author: | Goertz [ Tue Nov 21, 2017 3:01 pm ] |
Post subject: | Re: Create page labels and get page page by name. |
Thanks for the help! First time working with PDF's. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |