LEADTOOLS Forms (Leadtools.Forms.DocumentWriters assembly)

PdfCustomBookmark Structure

Show in webframe
Example 







Members 
Options to use when creating custom bookmarks based when creating Adobe Portable Document Format (PDF) documents.
Object Model
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
Copy Code  
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms.Ocr

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.Advantage, False)
      '  Start re-useing the RasterCodecs we have for performance
      ocrEngine.Startup(codecs, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)

      '  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"
Public Const OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 18\Bin\Common\OcrAdvantageRuntime"
End Class
using Leadtools.Forms.DocumentWriters;
using Leadtools.Forms.Ocr;
using Leadtools;
using Leadtools.Codecs;

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.Advantage, false))
   {
      // Start re-useing the RasterCodecs we have for performance
      ocrEngine.Startup(codecs, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);

      // 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";
public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 18\Bin\Common\OcrAdvantageRuntime";
}
Requirements

Target Platforms

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-2014 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