←Select platform

PdfCustomBookmark Structure

Summary
Options to use when creating custom bookmarks based when creating Adobe Portable Document Format (PDF) documents.
Syntax
C#
Objective-C
C++/CLI
Java
Python
[SerializableAttribute()] 
[DataContractAttribute()] 
public struct PdfCustomBookmark 
@interface LTPdfCustomBookmark : NSObject <NSCopying, NSCoding> 
public class PdfCustomBookmark 
[DataContractAttribute()] 
[SerializableAttribute()] 
public value class PdfCustomBookmark : public System.ValueType  
class PdfCustomBookmark: 
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

This example will use OCR to convert an input multipage TIF file to searachble PDF creating a custom bookmark for each page in the output PDF file.

C#
using Leadtools.Document.Writer; 
using Leadtools.Ocr; 
using Leadtools; 
using Leadtools.Codecs; 
 
 
public void OcrToPDFWithCustomBookmarksExample() 
{ 
   var tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Example.tif"); 
   var pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "out_Example.pdf"); 
 
   int pageCount; 
 
   // Get the input multi-page TIF file 
   using (var codecs = new RasterCodecs()) 
   { 
      codecs.Options.RasterizeDocument.Load.Resolution = 300; 
      CreateMultiPageTifFile(codecs, tifFileName); 
 
      // We are going to create a bookmark for each page, so get number of pages of input file 
      pageCount = codecs.GetTotalPages(tifFileName); 
   } 
 
   // Create the OCR engine 
   using (var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
   { 
      // Start re-using the RasterCodecs we have for performance 
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir); 
 
      // Get the DocumentWriter instance used in this OCR engine  
      var docWriter = ocrEngine.DocumentWriterInstance; 
 
      // Get the current PDF options, modify and then set it back  
      var pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; 
 
      pdfOptions.DocumentType = PdfDocumentType.PdfA; 
      pdfOptions.ImageOverText = true; 
 
      // Set bookmark options 
      pdfOptions.AutoBookmarksEnabled = false; 
      for (var pageNumber = 1; pageNumber <= pageCount; pageNumber++) 
      { 
         var bookmark = new PdfCustomBookmark(); 
         bookmark.Name = string.Format("Page {0}", pageNumber); 
         bookmark.PageNumber = pageNumber; 
         bookmark.LevelNumber = 0; 
         bookmark.XCoordinate = 0; 
         bookmark.YCoordinate = 0; 
         pdfOptions.CustomBookmarks.Add(bookmark); 
      } 
 
      docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions); 
 
      // ocr and save document with bookmark options applied 
      ocrEngine.AutoRecognizeManager.Run(tifFileName, pdfFileName, null, DocumentFormat.Pdf, null); 
   } 
} 
 
private void CreateMultiPageTifFile(RasterCodecs codecs, string tifFileName) 
{ 
   // Create a multi-page tif file from shipping Ocr1, Ocr2, Ocr3 and Ocr4.tif 
   var tifFileNameTemplate = Path.Combine(LEAD_VARS.ImagesDir, "Ocr{0}.tif"); 
 
   if (File.Exists(tifFileName)) 
      File.Delete(tifFileName); 
 
   RasterImage image = null; 
   for (var pageNumber = 1; pageNumber <= 4; pageNumber++) 
   { 
      var tempImage = codecs.Load(string.Format(tifFileNameTemplate, pageNumber)); 
 
      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:\LEADTOOLS22\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS22\Bin\Common\OcrLEADRuntime"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document.Writer Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.