Options to use when creating custom bookmarks based when creating Adobe Portable Document Format (PDF) documents.
[SerializableAttribute()][DataContractAttribute()]public struct PdfCustomBookmark
<DataContractAttribute()><SerializableAttribute()>Public Structure PdfCustomBookmarkInherits System.ValueType
@interface LTPdfCustomBookmark : NSObject <NSCopying, NSCoding> public class PdfCustomBookmark [DataContractAttribute()][SerializableAttribute()]public value class PdfCustomBookmark : public System.ValueType
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.
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.
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, "Example.pdf");int pageCount;// Get the input multi-page TIF fileusing (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 filepageCount = codecs.GetTotalPages(tifFileName);}// Create the OCR engineusing (var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false)){// Start re-using the RasterCodecs we have for performanceocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir);// Get the DocumentWriter instance used in this OCR enginevar docWriter = ocrEngine.DocumentWriterInstance;// Get the current PDF options, modify and then set it backvar pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;pdfOptions.DocumentType = PdfDocumentType.PdfA;pdfOptions.ImageOverText = true;// Set bookmark optionspdfOptions.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 appliedocrEngine.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.tifvar 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:\Users\Public\Documents\LEADTOOLS Images";public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime";}
Imports Leadtools.Document.WriterImports Leadtools.OcrImports LeadtoolsImports Leadtools.CodecsPublic Sub OcrToPDFWithCustomBookmarksExample()Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Example.tif")Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Example.pdf")Dim pageCount As Integer' Get the input multi-page TIF fileUsing codecs As New RasterCodecs()codecs.Options.RasterizeDocument.Load.Resolution = 30CreateMultiPageTifFile(codecs, tifFileName)' We are going to create a bookmark for each page, so get number of pages of input filepageCount = codecs.GetTotalPages(tifFileName)End Using' Create the OCR engineUsing ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False)' Start re-useing the RasterCodecs we have for performanceocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir)' Get the DocumentWriter instance used in this OCR engineDim docWriter As DocumentWriter = ocrEngine.DocumentWriterInstance' Get the current PDF options, modify and then set it backDim pdfOptions As PdfDocumentOptions = DirectCast(docWriter.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions)pdfOptions.DocumentType = PdfDocumentType.PdfApdfOptions.ImageOverText = True' Set bookmark optionspdfOptions.AutoBookmarksEnabled = FalseFor pageNumber As Integer = 1 To pageCountDim bookmark As New PdfCustomBookmark()bookmark.Name = String.Format("Page {0}", pageNumber)bookmark.PageNumber = pageNumberbookmark.LevelNumber = 0bookmark.XCoordinate = 0bookmark.YCoordinate = 0pdfOptions.CustomBookmarks.Add(bookmark)NextdocWriter.SetOptions(DocumentFormat.Pdf, pdfOptions)' ocr and save document with bookmark options appliedocrEngine.AutoRecognizeManager.Run(tifFileName, pdfFileName, Nothing, DocumentFormat.Pdf, Nothing)End UsingEnd SubPrivate Sub CreateMultiPageTifFile(codecs As RasterCodecs, tifFileName As String)' Create a multi-page tif file from shipping Ocr1, Ocr2, Ocr3 and Ocr4.tifDim tifFileNameTemplate As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr{0}.tif")If File.Exists(tifFileName) Then File.Delete(tifFileName)Dim image As RasterImage = NothingFor pageNumber As Integer = 1 To 4Dim tempImage As RasterImage = codecs.Load(String.Format(tifFileNameTemplate, pageNumber))If IsNothing(image) Thenimage = tempImageElseimage.AddPage(tempImage)tempImage.Dispose()End IfNextcodecs.Save(image, tifFileName, RasterImageFormat.CcittGroup4, 1)image.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime"End Class
Leadtools.Document.Writer Namespace
Programming with LEADTOOLS Document Writers
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
