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

PdfCustomBookmark Structure

Example 





Members 
Options to use when creating custom bookmarks based when creating Adobe Portable Document Format (PDF) documents. .NET support
Object Model
PdfCustomBookmark Structure
Syntax
public struct PdfCustomBookmark : System.ValueType 
'Declaration
 
Public Structure PdfCustomBookmark 
   Inherits System.ValueType
'Usage
 
Dim instance As PdfCustomBookmark
public class PdfCustomBookmark
JAVASCRIPT_NOSTRUCTS
public value class PdfCustomBookmark : public System.ValueType 
Remarks

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

Custom bookmarks will only be used if creating auto-bookmarks is disabled in the PDF options. So to use custom bookmarks, set the PdfDocumentOptions.AutoBookmarksEnabled property to false.

Example
 
Public Sub OcrToPDFWithCustomBookmarksExample()
      Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr.tif")
      Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr.pdf")
      Dim codecs As New RasterCodecs()

      '  Get the input multi-page TIF file
      CreateMultiPageTifFile(codecs, tifFileName)

      '  We are going to create a bookmark for each page, so get number of pages of input file
      Dim pageCount As Integer
      Using imageInfo As CodecsImageInfo = codecs.GetInformation(tifFileName, True)
         pageCount = imageInfo.TotalPages
      End Using

      '  Create the OCR engine
      Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Professional, False)
         '  Start re-useing the RasterCodecs we have for performance
         ocrEngine.Startup(codecs, Nothing, Nothing, Nothing)

         '  Get the DocumentWriter instance used in this OCR engine 
         Dim docWriter As DocumentWriter = ocrEngine.DocumentWriterInstance

         '  Get the current PDF options, modify and then set it back 
         Dim pdfOptions As PdfDocumentOptions = CType(docWriter.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions)

         pdfOptions.DocumentType = PdfDocumentType.PdfA
         pdfOptions.ImageOverText = True

         '  Set bookmark options
         pdfOptions.AutoBookmarksEnabled = False
         For i As Integer = 1 To pageCount
            Dim newBookmark As New PdfCustomBookmark()
            newBookmark.Name = String.Format("Page {0}", i)
            newBookmark.PageNumber = i
            newBookmark.LevelNumber = 0
            newBookmark.XCoordinate = 0
            newBookmark.YCoordinate = 0
            pdfOptions.CustomBookmarks.Add(newBookmark)
         Next

         docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions)

         '  ocr and save document with bookmark options applied
         ocrEngine.AutoRecognizeManager.Run(tifFileName, pdfFileName, Nothing, DocumentFormat.Pdf, Nothing)
      End Using

      codecs.Dispose()
   End Sub

   Private Sub CreateMultiPageTifFile(ByVal codecs As RasterCodecs, ByVal tifFileName As String)
      '  Create a multi-page tif file from shipping Ocr1, Ocr2, Ocr3 and Ocr4.tif
      Dim tifFileNameTemplate As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr{0}.tif")

      If File.Exists(tifFileName) Then
         File.Delete(tifFileName)
      End If

      Dim image As RasterImage = Nothing
      For i As Integer = 1 To 4
         Dim tempImage As RasterImage = codecs.Load(String.Format(tifFileNameTemplate, i))

         If IsNothing(image) Then
            image = tempImage
         Else
            image.AddPage(tempImage)
            tempImage.Dispose()
         End If
      Next

      codecs.Save(image, tifFileName, RasterImageFormat.CcittGroup4, 1)
      image.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void OcrToPDFWithCustomBookmarksExample()
   {
      string tifFileName = Path.Combine(LEAD_VARS.ImagesDir,"Ocr.tif");
      string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir,"Ocr.pdf");
      RasterCodecs codecs = new RasterCodecs();

      // Get the input multi-page TIF file
      CreateMultiPageTifFile(codecs, tifFileName);

      // We are going to create a bookmark for each page, so get number of pages of input file
      int pageCount;
      using(CodecsImageInfo imageInfo = codecs.GetInformation(tifFileName, true))
      {
         pageCount = imageInfo.TotalPages;
      }

      // Create the OCR engine
      using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Professional, false))
      {
         // Start re-useing the RasterCodecs we have for performance
         ocrEngine.Startup(codecs, null, null, null);

         // Get the DocumentWriter instance used in this OCR engine 
         DocumentWriter docWriter = ocrEngine.DocumentWriterInstance;

         // Get the current PDF options, modify and then set it back 
         PdfDocumentOptions pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;

         pdfOptions.DocumentType = PdfDocumentType.PdfA;
         pdfOptions.ImageOverText = true;

         // Set bookmark options
         pdfOptions.AutoBookmarksEnabled = false;
         for(int i = 1; i <= pageCount; i++)
         {
            PdfCustomBookmark newBookmark = new PdfCustomBookmark();
            newBookmark.Name = string.Format("Page {0}", i);
            newBookmark.PageNumber = i;
            newBookmark.LevelNumber = 0;
            newBookmark.XCoordinate = 0;
            newBookmark.YCoordinate = 0;
            pdfOptions.CustomBookmarks.Add(newBookmark);
         }

         docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions);

         // ocr and save document with bookmark options applied
         ocrEngine.AutoRecognizeManager.Run(tifFileName, pdfFileName, null, DocumentFormat.Pdf, null);
      }

      codecs.Dispose();
   }

   private void CreateMultiPageTifFile(RasterCodecs codecs, string tifFileName)
   {
      // Create a multi-page tif file from shipping Ocr1, Ocr2, Ocr3 and Ocr4.tif
      string tifFileNameTemplate = Path.Combine(LEAD_VARS.ImagesDir,"Ocr{0}.tif");

      if(File.Exists(tifFileName))
         File.Delete(tifFileName);

      RasterImage image = null;
      for(int i = 1; i <= 4; i++)
      {
         RasterImage tempImage = codecs.Load(string.Format(tifFileNameTemplate, i));

         if(image == null)
            image = tempImage;
         else
         {
            image.AddPage(tempImage);
            tempImage.Dispose();
         }
      }

      codecs.Save(image, tifFileName, RasterImageFormat.CcittGroup4, 1);
      image.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

PdfCustomBookmark 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