LEADTOOLS Leadtools.Documents.UI(Leadtools.Documents.UIアセンブリ)

フレームを表示

DocumentViewerクラス






メンバ 
LEADTOOLSドキュメントビューワ
オブジェクトモデル
構文
public class DocumentViewer 
'Declaration
 
Public Class DocumentViewer 
'Usage
 
Dim instance As DocumentViewer
public ref class DocumentViewer 
解説

ドキュメントビューワはLEADTOOLSラスターを使います、そして、ドキュメントは、キャッシュに格納して、最小の量のcodeでデスクトップまたはウェブでドキュメントの任意型を表示することができて、編集することができて、修正することができるアプリケーションを作成するのを許すためにSVGOCRアノテーション画像ビューワ技術をサポートします。

DocumentViewerは、ドキュメントビューワにより用いられる主要なクラスです。それはコントロール自体でありません、代わりに、必要なUIコントロールを作成することはユーザーにより提供される親コンテナを使います。これらのコンテナは、呼び出し元プラットフォーム ― たとえば、Windowsフォームのネイティブなコントロールや、HTML/JavaScriptのDIV要素 ― のネイティブコントロールです。

DocumentViewerは、以下のパーツを持っています:

サンプル

このサンプルは、Windowsフォームアプリケーションで機能的なDocumentViewerを作成するために示します。

Copy Code  
Imports Leadtools
Imports Leadtools.Controls
Imports Leadtools.Documents
Imports Leadtools.Documents.UI
Imports Leadtools.Codecs
Imports Leadtools.Caching
Imports Leadtools.Annotations.Core
Imports Leadtools.Forms.Ocr

<TestMethod> _
Public Sub DocumentViewer_Example()
   ' New Form to be used as our application
   Dim form As New MyForm()
   form.ShowDialog()
End Sub

Class MyForm
   Inherits Form
   Public Sub New()
      Me.Size = New Size(800, 800)
      Me.Text = "LEADTOOLS Document Viewer Example"
   End Sub

   Protected Overrides Sub OnLoad(e As EventArgs)
      If Not DesignMode Then
         ' Init OCR. This is optional and not required for the PDF document we are loading.
         ' But if image documents are loaded and text functionality is used, then we need OCR
         _ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
         _ocrEngine.Startup(Nothing, Nothing, Nothing, "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime")

         Init()
      End If

      MyBase.OnLoad(e)
   End Sub

   ' Our document viewer instance
   Private _documentViewer As DocumentViewer

   ' Optional OCR engine to use in the example
   Private _ocrEngine As IOcrEngine

   Private Sub Init()
      ' Initialize the user interface
      InitUI()

      ' Init the cache. This is optional, but it can speed up viewing of large documents
      ' if not needed, remove this section
      DocumentFactory.Cache = New FileCache()

      ' Init the document viewer, pass along the panels
      Dim createOptions As New DocumentViewerCreateOptions()
      ' The middle panel for the view
      createOptions.ViewContainer = Me.Controls.Find("middlePanel", False)(0)
      ' The left panel for the thumbnails
      createOptions.ThumbnailsContainer = Me.Controls.Find("leftPanel", False)(0)
      ' The right panel is for bookmarks
      createOptions.BookmarksContainer = Me.Controls.Find("rightPanel", False)(0)
      ' Not using annotations for now
      createOptions.UseAnnotations = False

      ' Create the document viewer
      _documentViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions)

      ' We prefer SVG viewing
      _documentViewer.View.PreferredItemType = DocumentViewerItemType.Svg

      ' Load a document
      Dim fileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Leadtools.pdf"
      Dim loadOptions As New LoadDocumentOptions()
      loadOptions.UseCache = Not IsNothing(DocumentFactory.Cache)
      Dim document As Document = DocumentFactory.LoadFromFile(fileName, loadOptions)

      AddHandler _documentViewer.Operation,
         Sub(sender, e)
            If e.Operation = DocumentViewerOperation.LoadingBookmarks Then
               ' Disable the bookmarks when we are loading, enable when we are done
               Dim rightPanel As Control = Me.Controls.Find("rightPanel", True)(0)
               If rightPanel.InvokeRequired Then
                  rightPanel.Invoke(DirectCast(Sub() rightPanel.Enabled = e.IsPostOperation, MethodInvoker))
               Else
                  rightPanel.Enabled = e.IsPostOperation
               End If
            End If
         End Sub

      ' If we have an OCR engine, use it
      document.Text.OcrEngine = _ocrEngine

      ' Set it in the viewer
      _documentViewer.SetDocument(document)

      ' Run pan/zoom
      Dim interactiveComboBox As ComboBox = CType(Me.Controls.Find("interactiveComboBox", True)(0), ComboBox)
      interactiveComboBox.SelectedItem = DocumentViewerCommands.InteractivePanZoom
   End Sub

   Private Sub InitUI()
      ' Add a panel on the left for the document viewer thumbnails part
      Dim leftPanel As New Panel()
      leftPanel.Name = "leftPanel"
      leftPanel.Width = 200
      leftPanel.Dock = DockStyle.Left
      leftPanel.BackColor = Color.Gray
      leftPanel.BorderStyle = BorderStyle.FixedSingle
      Me.Controls.Add(leftPanel)

      ' Add a panel to the right, this will work for the bookmarks or annotations part
      Dim rightPanel As New Panel()
      rightPanel.Name = "rightPanel"
      rightPanel.Width = 200
      rightPanel.Dock = DockStyle.Right
      rightPanel.BackColor = Color.LightBlue
      rightPanel.BorderStyle = BorderStyle.FixedSingle
      Me.Controls.Add(rightPanel)

      ' Add a panel to fill the rest, for the document viewer
      Dim middlePanel As New Panel()
      middlePanel.Name = "middlePanel"
      middlePanel.BackColor = Color.DarkGray
      middlePanel.BorderStyle = BorderStyle.None
      middlePanel.Dock = DockStyle.Fill
      Me.Controls.Add(middlePanel)

      ' Add a top panel to host our application controls
      Dim topPanel As New Panel()
      topPanel.Name = "topPanel"
      topPanel.Height = 100
      topPanel.Dock = DockStyle.Top
      topPanel.BorderStyle = BorderStyle.FixedSingle
      Me.Controls.Add(topPanel)

      middlePanel.BringToFront()

      ' Add buttons for the UI

      ' Combo box for interactive modes
      Dim interactiveComboBox As New ComboBox()
      interactiveComboBox.Name = "interactiveComboBox"
      interactiveComboBox.DropDownStyle = ComboBoxStyle.DropDownList
      ' The command names for the items so we can just run them
      interactiveComboBox.Items.Add(DocumentViewerCommands.InteractivePanZoom)
      interactiveComboBox.Items.Add(DocumentViewerCommands.InteractiveSelectText)
      AddHandler interactiveComboBox.SelectedIndexChanged,
         Sub(sender, e)
            Dim commandName As String = CType(interactiveComboBox.SelectedItem, String)
            _documentViewer.Commands.Run(commandName)
         End Sub
      topPanel.Controls.Add(interactiveComboBox)

      ' Generic label for information used by the examples
      Dim infoLabel As New Label()
      infoLabel.Name = "infoLabel"
      infoLabel.Text = "Info..."
      infoLabel.AutoSize = False
      infoLabel.Width = 400
      infoLabel.Left = interactiveComboBox.Right + 20
      topPanel.Controls.Add(infoLabel)

      Dim exampleButton As New Button()
      exampleButton.Top = interactiveComboBox.Bottom + 2
      exampleButton.Name = "exampleButton"
      exampleButton.Text = "&Example"
      AddHandler exampleButton.Click, Sub(sender, e) Example(exampleButton)
      topPanel.Controls.Add(exampleButton)
   End Sub

   Private Sub Example(exampleButton As Button)
      ' Add the example code here
      MessageBox.Show(Me, "Ready")
   End Sub
End Class
using Leadtools;
using Leadtools.Controls;
using Leadtools.Documents;
using Leadtools.Documents.UI;
using Leadtools.Codecs;
using Leadtools.Caching;
using Leadtools.Annotations.Core;
using Leadtools.Forms.Ocr;

[TestMethod]
public void DocumentViewer_Example()
{
   // New Form to be used as our application
   var form = new MyForm();
   form.ShowDialog();
}
class MyForm : Form
{
   public MyForm()
   {
      this.Size = new Size(800, 800);
      this.Text = "LEADTOOLS Document Viewer Example";
   }

   protected override void OnLoad(EventArgs e)
   {
      if (!DesignMode)
      {
         // Init OCR. This is optional and not required for the PDF document we are loading.
         // But if image documents are loaded and text functionality is used, then we need OCR
         _ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
         _ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime");

         Init();
      }

      base.OnLoad(e);
   }

   // Our document viewer instance
   private DocumentViewer _documentViewer;

   // Optional OCR engine to use in the example
   private IOcrEngine _ocrEngine;

   private void Init()
   {
      // Initialize the user interface
      InitUI();

      // Init the cache. This is optional, but it can speed up viewing of large documents
      // if not needed, remove this section
      DocumentFactory.Cache = new FileCache();

      // Init the document viewer, pass along the panels
      var createOptions = new DocumentViewerCreateOptions
      {
         // The middle panel for the view
         ViewContainer = this.Controls.Find("middlePanel", false)[0],
         // The left panel for the thumbnails
         ThumbnailsContainer = this.Controls.Find("leftPanel", false)[0],
         // The right panel is for bookmarks
         BookmarksContainer = this.Controls.Find("rightPanel", false)[0],
         // Not using annotations for now
         UseAnnotations = false
      };

      // Create the document viewer
      _documentViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions);

      // We prefer SVG viewing
      _documentViewer.View.PreferredItemType = DocumentViewerItemType.Svg;

      // Load a document
      var fileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Leadtools.pdf";
      var document = DocumentFactory.LoadFromFile(
         fileName,
         new LoadDocumentOptions { UseCache = DocumentFactory.Cache != null });

      _documentViewer.Operation += (sender, e) =>
      {
         if (e.Operation == DocumentViewerOperation.LoadingBookmarks)
         {
            // Disable the bookmarks when we are loading, enable when we are done
            var rightPanel = this.Controls.Find("rightPanel", true)[0];
            if (rightPanel.InvokeRequired)
            {
               rightPanel.Invoke((MethodInvoker)delegate { rightPanel.Enabled = e.IsPostOperation; });
            }
            else
            {
               rightPanel.Enabled = e.IsPostOperation;
            }
         }
      };

      // If we have an OCR engine, use it
      document.Text.OcrEngine = _ocrEngine;

      // Set it in the viewer
      _documentViewer.SetDocument(document);

      // Run pan/zoom
      var interactiveComboBox = this.Controls.Find("interactiveComboBox", true)[0] as ComboBox;
      interactiveComboBox.SelectedItem = DocumentViewerCommands.InteractivePanZoom;
   }

   private void InitUI()
   {
      // Add a panel on the left for the document viewer thumbnails part
      var leftPanel = new Panel();
      leftPanel.Name = "leftPanel";
      leftPanel.Width = 200;
      leftPanel.Dock = DockStyle.Left;
      leftPanel.BackColor = Color.Gray;
      leftPanel.BorderStyle = BorderStyle.FixedSingle;
      this.Controls.Add(leftPanel);

      // Add a panel to the right, this will work for the bookmarks or annotations part
      var rightPanel = new Panel();
      rightPanel.Name = "rightPanel";
      rightPanel.Width = 200;
      rightPanel.Dock = DockStyle.Right;
      rightPanel.BackColor = Color.LightBlue;
      rightPanel.BorderStyle = BorderStyle.FixedSingle;
      this.Controls.Add(rightPanel);

      // Add a panel to fill the rest, for the document viewer
      var middlePanel = new Panel();
      middlePanel.Name = "middlePanel";
      middlePanel.BackColor = Color.DarkGray;
      middlePanel.BorderStyle = BorderStyle.None;
      middlePanel.Dock = DockStyle.Fill;
      this.Controls.Add(middlePanel);

      // Add a top panel to host our application controls
      var topPanel = new Panel();
      topPanel.Name = "topPanel";
      topPanel.Height = 100;
      topPanel.Dock = DockStyle.Top;
      topPanel.BorderStyle = BorderStyle.FixedSingle;
      this.Controls.Add(topPanel);

      middlePanel.BringToFront();

      // Add buttons for the UI

      // Combo box for interactive modes
      var interactiveComboBox = new ComboBox();
      interactiveComboBox.Name = "interactiveComboBox";
      interactiveComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
      // The command names for the items so we can just run them
      interactiveComboBox.Items.Add(DocumentViewerCommands.InteractivePanZoom);
      interactiveComboBox.Items.Add(DocumentViewerCommands.InteractiveSelectText);
      interactiveComboBox.SelectedIndexChanged += (sender, e) =>
      {
         var commandName = interactiveComboBox.SelectedItem as string;
         _documentViewer.Commands.Run(commandName);
      };
      topPanel.Controls.Add(interactiveComboBox);

      // Generic label for information used by the examples
      var infoLabel = new Label();
      infoLabel.Name = "infoLabel";
      infoLabel.Text = "Info...";
      infoLabel.AutoSize = false;
      infoLabel.Width = 400;
      infoLabel.Left = interactiveComboBox.Right + 20;
      topPanel.Controls.Add(infoLabel);

      var exampleButton = new Button();
      exampleButton.Top = interactiveComboBox.Bottom + 2;
      exampleButton.Name = "exampleButton";
      exampleButton.Text = "&Example";
      exampleButton.Click += (sender, e) => Example(exampleButton);
      topPanel.Controls.Add(exampleButton);
   }

   private void Example(Button exampleButton)
   {
      // Add the example code here
      MessageBox.Show(this, "Ready");
   }
}
必要条件

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

参照

参照

DocumentViewerメンバ
Leadtools.Documents.UI名前空間
LEADTOOLSドキュメントビューワの使用
ドキュメントビューワのコマンド
ドキュメントビューワの操作
ドキュメントライブラリ機能
LEADTOOLSドキュメントライブラリを使用したロード
LEADTOOLSドキュメントライブラリを使用したアップロード
ドキュメントライブラリ座標システム
ドキュメントライブラリによるテキストの解析
ドキュメントライブラリによるバーコード処理
ドキュメントライブラリを使用した暗号化ファイルのロード
LEADTOOLSドキュメントビューワの使用

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