Leadtools.Annotations Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
AnnPrinter Class
See Also  Members   Example 
Leadtools.Annotations Namespace : AnnPrinter Class



Supports printing of an RasterImage and a AnnContainer.

Syntax

Visual Basic (Declaration) 
Public Class AnnPrinter 
   Inherits RasterImagePrinter
Visual Basic (Usage)Copy Code
Dim instance As AnnPrinter
C# 
public class AnnPrinter : RasterImagePrinter 
C++/CLI 
public ref class AnnPrinter : public RasterImagePrinter 

Example

This example loads an image, creates annotations, and prints.

Visual BasicCopy Code
Private myImage As RasterImage
Private myContainer As AnnContainer
Private Sub AnnPrinter_AnnPrinter()
   ' load an image
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()
   myImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Sample1.cmp")
   RasterCodecs.Shutdown()
   ' create a new container and add a few objects
   myContainer = New AnnContainer()
   myContainer.Bounds = New AnnRectangle(0, 0, myImage.Width, myImage.Height)

   Dim lineObj As AnnLineObject = New AnnLineObject()
   lineObj.StartPoint = New AnnPoint(100, 100, AnnUnit.Pixel)
   lineObj.EndPoint = New AnnPoint(200, 300, AnnUnit.Pixel)
   lineObj.Pen = New AnnPen(Color.Red, New AnnLength(4, AnnUnit.Pixel))
   myContainer.Objects.Add(lineObj)

   Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
   rectObj.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel)
   rectObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
   rectObj.Brush = New AnnSolidBrush(Color.Yellow)
   myContainer.Objects.Add(rectObj)

   ' intitialize a new PrintDocument object
   If Not PrinterSettings.InstalledPrinters Is Nothing AndAlso PrinterSettings.InstalledPrinters.Count > 0 Then
      Dim printDocument As PrintDocument = New PrintDocument()
      AddHandler printDocument.PrintPage, AddressOf PrintDocument_PrintPage
      printDocument.Print()
   End If

   ' dispose the image
   myImage.Dispose()
End Sub

Private Sub PrintDocument_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
   Dim printer As AnnPrinter = New AnnPrinter()

   ' We want normal size (not zoomed) but centered
   printer.SizeMode = RasterPaintSizeMode.Fit
   printer.HorizontalAlignMode = RasterPaintAlignMode.Center
   printer.VerticalAlignMode = RasterPaintAlignMode.Center

   ' print the whole image
   printer.ImageRectangle = Rectangle.Empty

   ' use maximum page
   printer.PageRectangle = RectangleF.Empty

   ' Win32 GDI printing and scale to gray
   Dim props As RasterPaintProperties = RasterPaintProperties.Default
   props.PaintEngine = RasterPaintEngine.Gdi
   props.PaintDisplayMode = props.PaintDisplayMode Or RasterPaintDisplayModeFlags.ScaleToGray
   printer.PaintProperties = props
   printer.Print(myImage, myImage.Page, myContainer, e)
End Sub
C#Copy Code
RasterImage myImage; 
AnnContainer myContainer; 
private void AnnPrinter_AnnPrinter() 

   // load an image 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   string fileName = LeadtoolsExamples.Common.ImagesPath.Path + "Sample1.cmp"; 
   myImage = codecs.Load(fileName); 
   RasterCodecs.Shutdown(); 
   // create a new container and add a few objects 
   myContainer = new AnnContainer(); 
   myContainer.Bounds = new AnnRectangle(0, 0, myImage.Width, myImage.Height); 
 
   AnnLineObject lineObj = new AnnLineObject(); 
   lineObj.StartPoint = new AnnPoint(100, 100, AnnUnit.Pixel); 
   lineObj.EndPoint = new AnnPoint(200, 300, AnnUnit.Pixel); 
   lineObj.Pen = new AnnPen(Color.Red, new AnnLength(4, AnnUnit.Pixel)); 
   myContainer.Objects.Add(lineObj); 
 
   AnnRectangleObject rectObj = new AnnRectangleObject(); 
   rectObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel); 
   rectObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel)); 
   rectObj.Brush = new AnnSolidBrush(Color.Yellow); 
   myContainer.Objects.Add(rectObj); 
 
   // intitialize a new PrintDocument object 
   if(PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0) 
   { 
      PrintDocument printDocument = new PrintDocument(); 
      printDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage); 
      printDocument.Print(); 
   } 
 
   // dispose the image 
   myImage.Dispose(); 

 
private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e) 

   AnnPrinter printer = new AnnPrinter(); 
 
   // We want normal size (not zoomed) but centered 
   printer.SizeMode = RasterPaintSizeMode.Fit; 
   printer.HorizontalAlignMode = RasterPaintAlignMode.Center; 
   printer.VerticalAlignMode = RasterPaintAlignMode.Center; 
 
   // print the whole image 
   printer.ImageRectangle = Rectangle.Empty; 
 
   // use maximum page 
   printer.PageRectangle = RectangleF.Empty; 
 
   // Win32 GDI printing and scale to gray 
   RasterPaintProperties props = RasterPaintProperties.Default; 
   props.PaintEngine = RasterPaintEngine.Gdi; 
   props.PaintDisplayMode |= RasterPaintDisplayModeFlags.ScaleToGray; 
   printer.PaintProperties = props; 
   printer.Print(myImage, myImage.Page, myContainer,e); 
}

Remarks

The AnnPrinter class derives from RasterImagePrinter to make the process of printing an AnnContainer on top of an RasterImage easier.

Printing using the .NET framework involves adding a handler to the PrintPage event. In that event handler, you set up a new instance of the AnnPrinter class, set up its properties as desired, and then call the Print method passing it the RasterImage to print, the image page number, the AnnContainer containing the annotation objects to be printed and the PrintPageEventArgs object obtained through your PrintPageEventHandler.

Inheritance Hierarchy

System.Object
   Leadtools.WinForms.RasterImagePrinter
      Leadtools.Annotations.AnnPrinter

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

Leadtools.Annotations requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features