LEADTOOLS Forms (Leadtools.Forms.DocumentWriters assembly)
LEAD Technologies, Inc

PdfAutoBookmark Structure

Example 





Members 
Options to use when creating bookmarks in automatic way based on font information of the document when creating Adobe Portable Document Format (PDF) documents. .NET support
Object Model
PdfAutoBookmark Structure
Syntax
public struct PdfAutoBookmark : System.ValueType 
'Declaration
 
Public Structure PdfAutoBookmark 
   Inherits System.ValueType
'Usage
 
Dim instance As PdfAutoBookmark
public class PdfAutoBookmark
JAVASCRIPT_NOSTRUCTS
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:

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:

Example
 
' 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
// 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()
   {
      // 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";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

PdfAutoBookmark Members
Leadtools.Forms.DocumentWriters Namespace
DocumentWriter Class
Programming with LEADTOOLS Document Writers
Files to be Included with Your Application
Unlocking Special LEAD Features

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

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