←Select platform

CustomBookmarks Property

Summary
List of the custom (user) bookmarks to use when creating PDF documents.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public IList<PdfCustomBookmark> CustomBookmarks { get; } 
@property (nonatomic, strong, nullable) NSArray<LTPdfCustomBookmark *> *customBookmarks; 
public List<PdfCustomBookmark> getCustomBookmarks() 
public: 
property IList<PdfCustomBookmark>^ CustomBookmarks { 
   IList<PdfCustomBookmark>^ get(); 
} 
CustomBookmarks # get  (PdfDocumentOptions) 

Property Value

A list of PdfCustomBookmark that represent the custom (user) bookmarks to add to the final PDF document.

Remarks

For more information, refer to PdfCustomBookmark

Example
C#
Java
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void ocrToPDFWithCustomBookmarksExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   final String OCR_LEAD_RUNTIME_DIR = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime"; 
 
   String tifFileName = combine(LEAD_VARS_IMAGES_DIR, "Example.tif"); 
   String pdfFileName = combine(LEAD_VARS_IMAGES_DIR, "out_Example.pdf"); 
 
   // Get the input multi-page TIF file 
   RasterCodecs codecs = new RasterCodecs(); 
 
   codecs.getOptions().getRasterizeDocument().getLoad().setResolution(300); 
   createMultiPageTifFile(codecs, tifFileName); 
 
   // We are going to create a bookmark for each page, so get number of pages of 
   // input file 
   int pageCount = codecs.getTotalPages(tifFileName); 
 
   // Create the OCR engine 
   OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
 
   // Start re-using the RasterCodecs we have for performance 
   ocrEngine.startup(null, null, null, OCR_LEAD_RUNTIME_DIR); 
 
   // Get the DocumentWriter instance used in this OCR engine 
   DocumentWriter docWriter = ocrEngine.getDocumentWriterInstance(); 
 
   // Get the current PDF options, modify and then set it back 
   PdfDocumentOptions pdfOptions = (PdfDocumentOptions) docWriter.getOptions(DocumentFormat.PDF); 
 
   pdfOptions.setDocumentType(PdfDocumentType.PDFA); 
   pdfOptions.setImageOverText(true); 
 
   // Set bookmark options 
   pdfOptions.setAutoBookmarksEnabled(false); 
 
   for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) { 
      PdfCustomBookmark bookmark = new PdfCustomBookmark(); 
      bookmark.setName(String.format("Page %s%n", pageNumber)); 
      bookmark.setPageNumber(pageNumber); 
      bookmark.setLevelNumber(0); 
      bookmark.setXCoordinate(0); 
      bookmark.setYCoordinate(0); 
      pdfOptions.getCustomBookmarks().add(bookmark); 
   } 
 
   docWriter.setOptions(DocumentFormat.PDF, pdfOptions); 
 
   // ocr and save document with bookmark options applied 
   ocrEngine.getAutoRecognizeManager().run(tifFileName, pdfFileName, DocumentFormat.PDF, null); 
 
   assertTrue(new File(pdfFileName).exists()); 
   System.out.printf("Command run, file saved to %s", pdfFileName); 
} 
 
private void createMultiPageTifFile(RasterCodecs codecs, String tifFileName) { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   // Create a multi-page tif file from shipping Ocr1, Ocr2, Ocr3 and Ocr4.tif 
   String tifFileNameTemplate = combine(LEAD_VARS_IMAGES_DIR, "Ocr%s.tif"); 
 
   File tifFile = new File(tifFileName); 
   if (tifFile.exists()) { 
      tifFile.delete(); 
   } 
 
   RasterImage image = null; 
 
   for (int pageNumber = 1; pageNumber <= 4; pageNumber++) { 
      RasterImage tempImage = codecs.load(String.format(tifFileNameTemplate, pageNumber)); 
      if (image == null) { 
         image = tempImage; 
      } else { 
         image.addPage(tempImage); 
         tempImage.dispose(); 
      } 
   } 
 
   codecs.save(image, tifFileName, RasterImageFormat.CCITT_GROUP4, 1); 
   image.dispose(); 
 
   System.out.println("Document created and saved to: " + tifFileName); 
   assertTrue(new File(tifFileName).exists()); 
} 
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:\LEADTOOLS23\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.8.21
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 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.