←Select platform

PdfAutoBookmark Structure

Summary

Options to use when creating bookmarks in automatic way based on font information of the document when creating Adobe Portable Document Format (PDF) documents.

Syntax

C#
VB
Java
Objective-C
WinRT C#
C++
[SerializableAttribute()] 
[DataContractAttribute()] 
public struct PdfAutoBookmark 
<DataContractAttribute()> 
<SerializableAttribute()> 
Public Structure PdfAutoBookmark  
   Inherits System.ValueType 
[DataContractAttribute()] 
[SerializableAttribute()] 
public class PdfAutoBookmark 
@interface LTPdfAutoBookmark : NSObject <NSCopying, NSCoding> 
public class PdfAutoBookmark 
JAVASCRIPT_NOSTRUCTS 
[DataContractAttribute()] 
[SerializableAttribute()] 
public value class PdfAutoBookmark : public System.ValueType  

Remarks

Use the PdfAutoBookmark structure with PdfDocumentOptions when saving a document using the DocumentFormat.Pdf format.

This class allows for the creation of bookmarks, which can be used to mark parts of a document for quick access. This can be done with documents that have been consistently formatted in outline or chapter form with sections and sub-sections, where each level uses unique font formatting to indicate each section.

The Document Writer Auto Bookmark feature will create bookmarks automatically for well structured documents that have a unique fonts for its table of contents. The document must be constructed with this kind of convention in mind in order for the Auto book-marking feature to work properly.

For example assume you have a document that have the following in its table of contents:

  • Set of Chapter titles that come with font: Arial17pt Bold
  • Set of Section titles which are parts of chapters and come with font: Tahoma 13pt
  • Set of Sub Section titles which come with font: Times New Roman 12pt Italic

To set the bookmarks for a document, first set the number of levels of bookmarks that you want. "Levels" represent the hierarchy of the bookmarks in the resultant bookmark outline. In our example there are three levels to be turned into bookmarks, so the number of Levels is 3 and must be set in the PdfDocumentOptions.TotalBookmarkLevels property.

To generate the auto bookmarks, you must first set PdfDocumentOptions.AutoBookmarksEnabled to true.

For first level of bookmark, you should set the following: FontFaceName to "Arial", UseStyles to true, BoldStyle to true, ItalicStyle to false, and FontHeight to 17.

For second level of bookmark, you should the following: FontFaceName to "Tahoma", UseStyles to false, and FontHeight equal to 13.

For third level of bookmark, you should set the following: FontFaceName to "Times New Roman", UseStyles to true, BoldStyle to false, ItalicStyle to true, and FontHeight equal to 12.

Notes:

  • The order of fonts is same as the order of levels (i.e. the first font will be in level 1, the 2nd in level 2 and so on).
  • Font selections should not conflict. Selecting "Arial" 17pt with same styles for both level1 and level2 will not work. Each level setting should be unique.
  • The maximum number of bookmarks cannot be greater than 10 levels and is limited by the number of unique fonts available in the loaded document. In the example used, it is limited to 3.

Note that this format does not support calling DocumentWriter.InsertPage.

Example

This example will create a new Adobe Portable Document Format document (PDF) file using the various supported options.

C#
VB
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Forms.Ocr; 
using Leadtools; 
using Leadtools.Codecs; 
 
public void PdfDocumentOptionsExample() 
{ 
   var inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.docx"); 
   var outputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Example.pdf"); 
 
   // Setup a new RasterCodecs object 
   var codecs = new RasterCodecs(); 
   codecs.Options.RasterizeDocument.Load.Resolution = 300; 
 
   // Get the number of pages in the input document 
   var pageCount = codecs.GetTotalPages(inputFileName); 
 
   // Create a new instance of the LEADTOOLS Document Writer 
   var docWriter = new DocumentWriter(); 
 
   // Change the PDF options 
   var pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; 
   pdfOptions.DocumentType = PdfDocumentType.Pdf; 
   pdfOptions.FontEmbedMode = DocumentFontEmbedMode.None; 
   pdfOptions.ImageOverText = false; 
   pdfOptions.Linearized = false; 
   pdfOptions.Title = "Add your title here"; 
   pdfOptions.Subject = "Add your subject here"; 
   pdfOptions.Keywords = "Add your keywords here"; 
   pdfOptions.Author = "Add author name here"; 
   pdfOptions.Protected = true; 
   pdfOptions.UserPassword = "User password"; 
   pdfOptions.OwnerPassword = "Owner password"; 
   pdfOptions.EncryptionMode = PdfDocumentEncryptionMode.RC128Bit; 
   pdfOptions.PrintEnabled = false; 
   pdfOptions.HighQualityPrintEnabled = true; 
   pdfOptions.CopyEnabled = false; 
   pdfOptions.EditEnabled = true; 
   pdfOptions.AnnotationsEnabled = true; 
   pdfOptions.AssemblyEnabled = false; 
   pdfOptions.OneBitImageCompression = OneBitImageCompressionType.Flate; 
   pdfOptions.ColoredImageCompression = ColoredImageCompressionType.FlateJpeg; 
   pdfOptions.QualityFactor = 2; 
 
   // Use default resolution 
   pdfOptions.DocumentResolution = 0; 
   pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed; 
 
   // Setup empty page size (Letter size) 
   pdfOptions.EmptyPageWidth = 8.5; 
   pdfOptions.EmptyPageHeight = 11; 
   pdfOptions.EmptyPageResolution = 300; 
 
   docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions); 
 
   // Create a new PDF document 
   Console.WriteLine("Creating new PDF document: {0}", outputFileName); 
   docWriter.BeginDocument(outputFileName, DocumentFormat.Pdf); 
 
   // Loop through all the pages 
   for (var pageNumber = 1; pageNumber <= pageCount; pageNumber++) 
   { 
      // Get the page as SVG 
      Console.WriteLine("Loading page {0}", pageNumber); 
      var page = new DocumentSvgPage(); 
      page.SvgDocument = codecs.LoadSvg(inputFileName, pageNumber, null); 
 
      // Add the page 
      Console.WriteLine("Adding page {0}", pageNumber); 
      docWriter.AddPage(page); 
 
      page.SvgDocument.Dispose(); 
   } 
 
   // Finally finish writing the PDF file on disk 
   docWriter.EndDocument(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools.Forms.DocumentWriters 
Imports Leadtools.Forms.Ocr 
Imports Leadtools 
Imports Leadtools.Codecs 
 
Public Sub PdfDocumentOptionsExample() 
   Dim inputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.docx") 
   Dim outputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Example.pdf") 
 
   ' Setup a new RasterCodecs object 
   Dim codecs As New RasterCodecs() 
   codecs.Options.RasterizeDocument.Load.Resolution = 300 
 
   ' Get the number of pages in the input document 
   Dim pageCount As Integer = codecs.GetTotalPages(inputFileName) 
 
   ' Create a new instance of the LEADTOOLS Document Writer 
   Dim docWriter As New DocumentWriter() 
 
   ' Change the PDF options 
   Dim pdfOptions As PdfDocumentOptions = DirectCast(docWriter.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions) 
   pdfOptions.DocumentType = PdfDocumentType.Pdf 
   pdfOptions.FontEmbedMode = DocumentFontEmbedMode.None 
   pdfOptions.ImageOverText = False 
   pdfOptions.Linearized = False 
   pdfOptions.Title = "Add your title here" 
   pdfOptions.Subject = "Add your subject here" 
   pdfOptions.Keywords = "Add your keywords here" 
   pdfOptions.Author = "Add author name here" 
   pdfOptions.Protected = True 
   pdfOptions.UserPassword = "User password" 
   pdfOptions.OwnerPassword = "Owner password" 
   pdfOptions.EncryptionMode = PdfDocumentEncryptionMode.RC128Bit 
   pdfOptions.PrintEnabled = False 
   pdfOptions.HighQualityPrintEnabled = True 
   pdfOptions.CopyEnabled = False 
   pdfOptions.EditEnabled = True 
   pdfOptions.AnnotationsEnabled = True 
   pdfOptions.AssemblyEnabled = False 
   pdfOptions.OneBitImageCompression = OneBitImageCompressionType.Flate 
   pdfOptions.ColoredImageCompression = ColoredImageCompressionType.FlateJpeg 
   pdfOptions.QualityFactor = 2 
 
   ' Use default resolution 
   pdfOptions.DocumentResolution = 0 
   pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed 
 
   ' Setup empty page size (Letter size) 
   pdfOptions.EmptyPageWidth = 8.5 
   pdfOptions.EmptyPageHeight = 11 
   pdfOptions.EmptyPageResolution = 300 
 
   docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions) 
 
   ' Create a new PDF document 
   Console.WriteLine("Creating new PDF document: {0}", outputFileName) 
   docWriter.BeginDocument(outputFileName, DocumentFormat.Pdf) 
 
   ' Loop through all the pages 
   For pageNumber As Integer = 1 To pageCount 
      ' Get the page as SVG 
      Console.WriteLine("Loading page {0}", pageNumber) 
      Dim page As New DocumentSvgPage() 
      page.SvgDocument = codecs.LoadSvg(inputFileName, pageNumber, Nothing) 
 
      ' Add the page 
      Console.WriteLine("Adding page {0}", pageNumber) 
      docWriter.AddPage(page) 
 
      page.SvgDocument.Dispose() 
   Next 
 
   ' Finally finish writing the PDF file on disk 
   docWriter.EndDocument() 
   codecs.Dispose() 
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 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Forms.DocumentWriters Assembly