DocumentViewerView Class (original) (raw)
Summary
Manages the main content view in this document viewer.
Syntax
public class DocumentViewerView : IDisposable
public:
ref class DocumentViewerView
Example
Start with the example created in DocumentViewer, remove all the code in the Example function and add the code below.
After the user clicks the Example button, we will draw a label for the page number at the bottom of each page.
using Leadtools;
using Leadtools.Controls;
using Leadtools.Document;
using Leadtools.Document.Viewer;
using Leadtools.Codecs;
using Leadtools.Caching;
using Leadtools.Annotations.Engine;
using Leadtools.Ocr;
// Disable the example button, this should only run once
exampleButton.Enabled = false;
// Get the view
var view = _documentViewer.View;
// Get its image viewer
var imageViewer = view.ImageViewer;
// Hook to the PostRender
imageViewer.PostRenderItem += (sender, e) =>
{
// Get the image viewer item for the page
var item = e.Item;
// Get the current rectangle for the image
var bounds = imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Image, false);
// Build the text we want. The page number is the item index + 1
var pageNumber = imageViewer.Items.IndexOf(item) + 1;
var text = "Page " + pageNumber.ToString();
// Get the image transformation for this item
var transform = imageViewer.GetItemImageTransform(e.Item);
// Apply it to the context
var gstate = e.Context.Save();
using (var matrix = new System.Drawing.Drawing2D.Matrix(
(float)transform.M11,
(float)transform.M12,
(float)transform.M21,
(float)transform.M22,
(float)transform.OffsetX,
(float)transform.OffsetY))
{
e.Context.MultiplyTransform(matrix);
}
// Render the text at the bottom of the bounds
var flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom;
var rc = new Rectangle((int)bounds.X, (int)bounds.Y, (int)bounds.Width, (int)bounds.Height);
TextRenderer.DrawText(e.Context, text, imageViewer.Font, rc, Color.White, Color.Black, flags);
e.Context.Restore(gstate);
};
// Invalidate so our changes take effect the first time
view.Invalidate();