←Select platform

ParseDocumentStructure Method

Summary

Parses the Table of Content and internal links or jumps between the pages of the PDF file associated with this PDFDocument.

Syntax

C#
VB
Java
C++
public void ParseDocumentStructure( 
   PDFParseDocumentStructureOptions options 
) 

Public Sub ParseDocumentStructure( _ 
   ByVal options As PDFParseDocumentStructureOptions _ 
)  

public void parseDocumentStructure(int pdfParseDocumentStructureOptions) 

public: 
void ParseDocumentStructure(  
   PDFParseDocumentStructureOptions options 
)  

Parameters

options
Document structure parsing options.

Remarks

Use ParseDocumentStructure to parse the document structure of the PDF document. The document structure is the Table of Contents (TOC) represented by a list of PDF bookmark objects stored in the Bookmarks property and the internal links between pages (or jumps) found in the document stored in the InternalLinks property.

When you create a new PDFDocument object from a PDF file on disk, the Bookmarks and InternalLinks properties will not be parsed automatically their values will be null. To read these values, you must use ParseDocumentStructure. When this method returns, the Bookmarks property will be populated with a list of PDFBookmark objects for each bookmark item found in the document (or an empty list if the document does not contain any bookmarks). Similarly, the InternalLinks property will be populated with a list of PDFInternalLink objects for each internal link or jump between the pages found in the document (or an empty list of no such items exist).

The options controls which items are parsed. You can parse the bookmarks only, internal links only or all.

To write bookmarks to a PDF file, use the PDFFile.WriteBookmarks method.

Example

This example will read the document structure of a PDF file

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
using Leadtools.WinForms; 
 
public void PDFDocumentParseDocumentStructureExample() 
{ 
   string pdfFileName1 = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf"); 
   string pdfFileName2 = Path.Combine(LEAD_VARS.ImagesDir, @"Bookmarks.pdf"); 
 
   // Create a version of the source file with a few bookmarks 
   PDFFile file = new PDFFile(pdfFileName1); 
   // Load the pages 
   file.Load(); 
   List<PDFBookmark> bookmarks = new List<PDFBookmark>(); 
 
   // We will bookmarks for each page, cascading levels: 
   // Goto page 1 
   //    Goto page 2 
   //       Goto page 3 
   //          Goto page 4 
   int level = 0; 
   for (int i = 0; i < file.Pages.Count; i++) 
   { 
      PDFFilePage page = file.Pages[i]; 
 
      PDFBookmark bookmark = new PDFBookmark(); 
      bookmark.Title = "Goto page " + page.PageNumber.ToString(); 
      bookmark.BookmarkStyle = PDFBookmarkStyle.Plain; 
      bookmark.Level = level; 
      bookmark.TargetPageNumber = page.PageNumber; 
      bookmark.TargetPageFitType = PDFPageFitType.Default; 
      bookmark.TargetPosition = new PDFPoint(0, page.Height); 
      bookmark.TargetZoomPercent = 0; 
      bookmarks.Add(bookmark); 
 
      level++; 
      if (level > 8) 
      { 
         // Reset levels 
         level = 0; 
      } 
   } 
 
   file.WriteBookmarks(bookmarks, pdfFileName2); 
 
   // Create a document for the output file 
   using (PDFDocument document = new PDFDocument(pdfFileName2)) 
   { 
      // Now read the bookmarks and internal links in the document 
      document.ParseDocumentStructure(PDFParseDocumentStructureOptions.InternalLinks | PDFParseDocumentStructureOptions.Bookmarks); 
 
      Console.WriteLine("{0} bookmarks found:", document.Bookmarks.Count); 
      foreach (PDFBookmark bookmark in document.Bookmarks) 
      { 
         Console.WriteLine(" Title: {0}, Level: {1}, Target page: {2}", bookmark.Title, bookmark.Level, bookmark.TargetPageNumber); 
      } 
 
      Console.WriteLine("{0} Internal links found:", document.InternalLinks.Count); 
      foreach (PDFInternalLink internalLink in document.InternalLinks) 
      { 
         Console.WriteLine(" Source bounds: {0}, Target page: {1}", internalLink.SourceBounds, internalLink.TargetPageNumber); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 

Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Controls 
Imports Leadtools.Pdf 
Imports Leadtools.Svg 
Imports Leadtools.WinForms 
 
Public Sub PDFDocumentParseDocumentStructureExample() 
   Dim pdfFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf") 
   Dim pdfFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Bookmarks.pdf") 
 
   ' Create a version of the source file with a few bookmarks 
   Dim file As PDFFile = New PDFFile(pdfFileName1) 
   ' Load the pages 
   file.Load() 
   Dim bookmarks As List(Of PDFBookmark) = New List(Of PDFBookmark)() 
 
   ' We will bookmarks for each page, cascading levels: 
   ' Goto page 1 
   '    Goto page 2 
   '       Goto page 3 
   '          Goto page 4 
   Dim level As Integer = 0 
   Dim i As Integer = 0 
   Do While i < file.Pages.Count 
      Dim page As PDFFilePage = file.Pages(i) 
 
      Dim bookmark As PDFBookmark = New PDFBookmark() 
      bookmark.Title = "Goto page " & page.PageNumber.ToString() 
      bookmark.BookmarkStyle = PDFBookmarkStyle.Plain 
      bookmark.Level = level 
      bookmark.TargetPageNumber = page.PageNumber 
      bookmark.TargetPageFitType = PDFPageFitType.Default 
      bookmark.TargetPosition = New PDFPoint(0, page.Height) 
      bookmark.TargetZoomPercent = 0 
      bookmarks.Add(bookmark) 
 
      level += 1 
      If level > 8 Then 
         ' Reset levels 
         level = 0 
      End If 
      i += 1 
   Loop 
 
   file.WriteBookmarks(bookmarks, pdfFileName2) 
 
   ' Create a document for the output file 
   Using document As PDFDocument = New PDFDocument(pdfFileName2) 
      ' Now read the bookmarks and internal links in the document 
      document.ParseDocumentStructure(PDFParseDocumentStructureOptions.InternalLinks Or PDFParseDocumentStructureOptions.Bookmarks) 
 
      Console.WriteLine("{0} bookmarks found:", document.Bookmarks.Count) 
      For Each bookmark As PDFBookmark In document.Bookmarks 
         Console.WriteLine(" Title: {0}, Level: {1}, Target page: {2}", bookmark.Title, bookmark.Level, bookmark.TargetPageNumber) 
      Next bookmark 
 
      Console.WriteLine("{0} Internal links found:", document.InternalLinks.Count) 
      For Each internalLink As PDFInternalLink In document.InternalLinks 
         Console.WriteLine(" Source bounds: {0}, Target page: {1}", internalLink.SourceBounds, internalLink.TargetPageNumber) 
      Next internalLink 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 20.0.2018.6.20
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly