←Select platform

PDFParseDocumentStructureOptions Enumeration

Summary
Specifies options to use when parsing a PDF document structure.
Syntax
C#
C++/CLI
Java
Python
[SerializableAttribute()] 
[FlagsAttribute()] 
public enum PDFParseDocumentStructureOptions 
public final class PDFParseDocumentStructureOptions 
    extends java.lang.Enum<PDFParseDocumentStructureOptions> 
[FlagsAttribute()] 
[SerializableAttribute()] 
public enum class PDFParseDocumentStructureOptions  
class PDFParseDocumentStructureOptions(Enum): 
   None = 0 
   Bookmarks = 1 
   InternalLinks = 2 
   Images = 4 
   Fonts = 8 
   EmbeddedFiles = 16 
   All = 31 
Members
ValueMemberDescription
0x00000000None Do not parse anything.
0x00000001Bookmarks Parse the bookmarks that constitute the document's Table of Contents (TOC). This option populates the PDFDocument.Bookmarks property.
0x00000002InternalLinks Parse the internal links (or jumps) between the pages found in the document. This option populates the PDFDocument.InternalLinks property.
0x00000004Images Parse the images found in the document. This option populates the PDFDocument.Images property.
0x00000008Fonts Parse the fonts found in the document. This option populates the PDFDocument.Fonts property.
0x0000001FAll Parse bookmarks, internal links, images, fonts and embedded files.
0x00000010EmbeddedFiles Parse embedded files.
Remarks

The PDFParseDocumentStructureOptions enumeration is used as the type of the options parameter passed to the PDFDocument.ParseDocumentStructure method.

The structure of PDF document is its Table of Contents (TOC) which consists of the PDFBookmark objects saved in the document and the collection of the internal links (or jumps) between the pages that are found in all the pages (PDFInternalLink objects).

When a PDFDocument object is created, the value of PDFDocument.Bookmarks and PDFDocument.InternalLinks will be initialized to null. You must call the PDFDocument.ParseDocumentStructure method to parse the items of interest (determined by the PDFParseDocumentStructureOptions passed as the options parameter to the method). This is done for performance reasons and to make it possible to parse only the objects of interest.

You can parse either the bookmarks or the internal links or both of a PDF document using the PDFDocument.ParseDocumentStructure method. When the method returns, the PDFDocument will be updated as follows:

  • If PDFParseDocumentStructureOptions.Bookmarks is specified, then the PDFDocument.Bookmarks collection will be populated with a PDFBookmark object for each bookmark item found in the document. If no bookmarks are found in the document, PDFDocument.Bookmarks will be initialized with an empty collection (PDFDocument.Bookmarks.Count will be 0).

  • If PDFParseDocumentStructureOptions.InternalLinks is specified, then the PDFDocument.InternalLinks collection will be populated with a PDFInternalLink object for each internal link (or jump) item found in the document. If no internal links are found in the document, the PDFDocument.InternalLinks will be initialized with an empty collection (PDFDocument.InternalLinks.Count will be 0).

The values of PDFParseDocumentStructureOptions can be OR'ed together.

Example
C#
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:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

See Also

Reference

Leadtools.Pdf Namespace

Help Version 22.0.2023.7.10
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.