LEADTOOLSフォーム(Leadtools.Forms.DocumentWritersアセンブリ)

フレームを表示

PdfCustomBookmark構造体








メンバ 
Adobe Portable Document Format(PDF)ドキュメントを作成するとき、拠点を置くカスタムブックマーク作成時に使うオプション。
オブジェクトモデル
構文
[DataContractAttribute()]
[SerializableAttribute()]
public struct PdfCustomBookmark : System.ValueType 
'Declaration
 
<DataContractAttribute()>
<SerializableAttribute()>
Public Structure PdfCustomBookmark 
   Inherits System.ValueType
'Usage
 
Dim instance As PdfCustomBookmark
[DataContractAttribute()]
[SerializableAttribute()]
public class PdfCustomBookmark
@interface LTPdfCustomBookmark : NSObject <NSCopying, NSCoding>
public class PdfCustomBookmark
JAVASCRIPT_NOSTRUCTS
[DataContractAttribute()]
[SerializableAttribute()]
public value class PdfCustomBookmark : public System.ValueType 
解説

DocumentFormat.Pdf形式を用いてドキュメントを保存するとき、PdfDocumentOptionsPdfCustomBookmark構造体を使います。

カスタムブックマークは、PDFオプションで自動ブックマークの作成が無効になっている場合にのみ使用されます。そのため、カスタムブックマークを使用するには、PdfDocumentOptions.AutoBookmarksEnabledプロパティをfalseに設定します。

サンプル

このサンプルは、入力マルチページTIFファイルを出力PDFファイルにおけるページごとにカスタムブックマークを作成しているsearachble PDFに変換するために、OCRを使用します。

Copy Code  
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools.Forms.Ocr
Imports Leadtools
Imports Leadtools.Codecs

      
Public 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 file
   Using codecs As New RasterCodecs()
      codecs.Options.RasterizeDocument.Load.Resolution = 30
      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)
   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(Nothing, 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 = DirectCast(docWriter.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions)

      pdfOptions.DocumentType = PdfDocumentType.PdfA
      pdfOptions.ImageOverText = True

      ' Set bookmark options
      pdfOptions.AutoBookmarksEnabled = False
      For pageNumber As Integer = 1 To pageCount
         Dim bookmark As 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)
      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
End Sub

Private Sub CreateMultiPageTifFile(codecs As RasterCodecs, 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)

   Dim image As RasterImage = Nothing
   For pageNumber As Integer = 1 To 4
      Dim tempImage As RasterImage = codecs.Load(String.Format(tifFileNameTemplate, pageNumber))

      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 19\Bin\Common\OcrAdvantageRuntime"
End Class
using Leadtools.Forms.DocumentWriters;
using Leadtools.Forms.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 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.Advantage, false))
   {
      // Start re-useing the RasterCodecs we have for performance
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);

      // 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:\Users\Public\Documents\LEADTOOLS Images";
public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime";
}
必要条件

ターゲットプラットホーム

参照

参照

PdfCustomBookmarkメンバ
Leadtools.Forms.DocumentWriters名前空間
DocumentWriterクラス
LEADTOOLSドキュメントライタでのプログラミング
アプリケーションに含まれるファイル
特殊なLEAD機能のアンロック

Leadtools.Forms.DocumentWritersは、DocumentまたはMedicalツールキットのライセンスと、解除キーが必要です。詳細は、以下を参照してください。Imaging Pro/Document/Medicalの機能