LEADTOOLS Forms (Leadtools.Forms.DocumentWriters assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
PdfAutoBookmark Structure
See Also  Members   Example
Leadtools.Forms.DocumentWriters Namespace : PdfAutoBookmark Structure



The PdfAutoBookmark Structure is available as an add-on to the LEADTOOLS Document and Medical Imaging toolkits.

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

Object Model

PdfAutoBookmark Structure

Syntax

Visual Basic (Declaration) 
Public Structure PdfAutoBookmark 
   Inherits System.ValueType
Visual Basic (Usage)Copy Code
Dim instance As PdfAutoBookmark
C# 
public struct PdfAutoBookmark : System.ValueType 
C++/CLI 
public value class PdfAutoBookmark : public System.ValueType 

Example

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

Visual BasicCopy Code
' Windows API functions needed to load/delete an EMF
   <DllImport("gdi32.dll")> _
   Private Shared Function GetEnhMetaFile(ByVal lpszMetaFile As String) As IntPtr
   End Function
   <DllImport("gdi32.dll")> _
   Private Shared Function DeleteEnhMetaFile(ByVal hemf As IntPtr) As Boolean
   End Function

   Private Sub PdfDocumentOptionsExample()
      ' Unlock the support needed for LEADTOOLS Document Writers (with PDF output)
      RasterSupport.Unlock(RasterSupportType.DocumentWriters, "Replace with your own key here")
      RasterSupport.Unlock(RasterSupportType.DocumentWritersPdf, "Replace with your own key here")

      ' We are going to use RasterCodecs to load a TIF file
      Dim codecs As New RasterCodecs()

      ' Create a new instance of the LEADTOOLS Document Writer
      Dim docWriter As New DocumentWriter()

      Dim pdfFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Test1.pdf")
      Dim pdfFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Test2.pdf")

      Dim emfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf")
      Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")

      ' Create a new PDF document with: PDF and no image/text
      Dim pdfOptions As PdfDocumentOptions = DirectCast(docWriter.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions)
      pdfOptions.DocumentType = PdfDocumentType.Pdf
      pdfOptions.FontEmbedMode = DocumentFontEmbedMode.None
      pdfOptions.ImageOverText = False
      docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions)

      Console.WriteLine("Creating new PDF document: {0}", pdfFileName1)
      docWriter.BeginDocument(pdfFileName1, DocumentFormat.Pdf)

      ' Use the Windows API to load the EMF
      Dim emfHandle As IntPtr = GetEnhMetaFile(emfFileName)

      ' Add the page, notice we will not be using image/text feature (the default)
      Dim page As DocumentPage = DocumentPage.Empty
      page.EmfHandle = emfHandle
      page.Image = Nothing

      Console.WriteLine("Adding EMF page from: {0}", emfFileName)
      docWriter.AddPage(page)

      ' Use the Windows API to delete the EMF
      DeleteEnhMetaFile(emfHandle)

      ' Finally finish writing the PDF file on disk
      docWriter.EndDocument()

      ' Now create a new PDF document with: PDF/A and image/text
      pdfOptions = DirectCast(docWriter.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions)
      pdfOptions.DocumentType = PdfDocumentType.PdfA
      pdfOptions.FontEmbedMode = DocumentFontEmbedMode.All
      pdfOptions.ImageOverText = True
      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)

      Console.WriteLine("Creating new PDF document: {0}", pdfFileName2)
      docWriter.BeginDocument(pdfFileName2, DocumentFormat.Pdf)

      ' Use the Windows API to load the EMF
      emfHandle = GetEnhMetaFile(emfFileName)
      Dim image As RasterImage = codecs.Load(tifFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)

      ' Add the page, notice we will be using image/text feature
      page = DocumentPage.Empty
      page.EmfHandle = emfHandle
      page.Image = image

      Console.WriteLine("Adding EMF page from: {0}", emfFileName)
      docWriter.AddPage(page)

      ' Use the Windows API to delete the EMF
      DeleteEnhMetaFile(emfHandle)

      ' We don't need the image anymore
      image.Dispose()

      ' 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
C#Copy Code
// Windows API functions needed to load/delete an EMF
   [DllImport("gdi32.dll")]
   private static extern IntPtr GetEnhMetaFile(string lpszMetaFile);
   [DllImport("gdi32.dll")]
   private static extern bool DeleteEnhMetaFile(IntPtr hemf);
   private void PdfDocumentOptionsExample()
   {
      // Unlock the support needed for LEADTOOLS Document Writers (with PDF output)
      RasterSupport.Unlock(RasterSupportType.DocumentWriters, "Replace with your own key here");
      RasterSupport.Unlock(RasterSupportType.DocumentWritersPdf, "Replace with your own key here");

      // We are going to use RasterCodecs to load a TIF file
      RasterCodecs codecs = new RasterCodecs();

      // Create a new instance of the LEADTOOLS Document Writer
      DocumentWriter docWriter = new DocumentWriter();

      string pdfFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Test1.pdf");
      string pdfFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Test2.pdf");

      string emfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf");
      string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif");

      // Create a new PDF document with: PDF and no image/text
      PdfDocumentOptions 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);

      Console.WriteLine("Creating new PDF document: {0}", pdfFileName1);
      docWriter.BeginDocument(pdfFileName1, DocumentFormat.Pdf);

      // Use the Windows API to load the EMF
      IntPtr emfHandle = GetEnhMetaFile(emfFileName);

      // Add the page, notice we will not be using image/text feature (the default)
      DocumentPage page = DocumentPage.Empty;
      page.EmfHandle = emfHandle;
      page.Image = null;

      Console.WriteLine("Adding EMF page from: {0}", emfFileName);
      docWriter.AddPage(page);

      // Use the Windows API to delete the EMF
      DeleteEnhMetaFile(emfHandle);

      // Finally finish writing the PDF file on disk
      docWriter.EndDocument();

      // Now create a new PDF document with: PDF/A and image/text
      pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;
      pdfOptions.DocumentType = PdfDocumentType.PdfA;
      pdfOptions.FontEmbedMode = DocumentFontEmbedMode.All;
      pdfOptions.ImageOverText = true;
      docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions);

      Console.WriteLine("Creating new PDF document: {0}", pdfFileName2);
      docWriter.BeginDocument(pdfFileName2, DocumentFormat.Pdf);

      // Use the Windows API to load the EMF
      emfHandle = GetEnhMetaFile(emfFileName);
      RasterImage image = codecs.Load(tifFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);

      // Add the page, notice we will be using image/text feature
      page = DocumentPage.Empty;
      page.EmfHandle = emfHandle;
      page.Image = image;

      Console.WriteLine("Adding EMF page from: {0}", emfFileName);
      docWriter.AddPage(page);

      // Use the Windows API to delete the EMF
      DeleteEnhMetaFile(emfHandle);

      // We don't need the image anymore
      image.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";
}

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.

Inheritance Hierarchy

System.Object
   System.ValueType
      Leadtools.Forms.DocumentWriters.PdfAutoBookmark

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Leadtools.Forms.DocumentWriters requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features