The PdfCustomBookmark Structure is available as an add-on to the LEADTOOLS Document and Medical Imaging toolkits.
Options to use when creating custom bookmarks based when creating Adobe Portable Document Format (PDF) documents.
Visual Basic (Declaration) | |
---|---|
Public Structure PdfCustomBookmark Inherits System.ValueType |
Visual Basic (Usage) | ![]() |
---|---|
Dim instance As PdfCustomBookmark |
C# | |
---|---|
public struct PdfCustomBookmark : System.ValueType |
C++/CLI | |
---|---|
public value class PdfCustomBookmark : public System.ValueType |
This example will use OCR to convert an input multi-page TIF file to searachble PDF creating a custom bookmark for each page in the output PDF file.
Visual Basic | ![]() |
---|---|
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") RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here") RasterSupport.Unlock(RasterSupportType.OcrProfessional, "Replace with your own key here") RasterSupport.Unlock(RasterSupportType.OcrPdfOutput, "Replace with your own key here") 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 |
C# | ![]() |
---|---|
public void OcrToPDFWithCustomBookmarksExample() { string tifFileName = Path.Combine(LEAD_VARS.ImagesDir,"Ocr.tif"); string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir,"Ocr.pdf"); RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrProfessional, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrPdfOutput, "Replace with your own key here"); 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"; } |
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.
System.Object
System.ValueType
Leadtools.Forms.DocumentWriters.PdfCustomBookmark
Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7