ImageMan ActiveX
Printing Images

The image control provides complete support for high Quality printing on any Windows supported printer. The image size, placement and cropping can all be specified using properties in the image control. Images can also be printed along with other printed output and multiple images can be printed on a page.


Because of the way Visual Basic handles printing, the image control sends its data to the Visual Basic Printer object. By doing this the control can print the image at the Resolution of the printer instead of the screen Resolution as is the case with the PrintForm method. This also allows your application to use the Printer object methods, Print, Line, etc. to draw on the page.


The Dst properties, DstTop , DstLeft , DstRight and DstBottom, specify the placement of the image on the page. These are specified in the TWIPS or whatever the printer mapping mode is set to (in VB this would be the Printer object's ScaleMode property).


In addition to setting the Dst properties your application must also set the PrnHDC property of the Image control to the value of the Printer.hDC property.


Once these properties have been set, the image can be printed by invoking PrintImage method.


The following Visual Basic code fragment sets prints an image sized to 2"x2" on the page:


Const TWIPS = 1440

' Print a space to initialize the VB printer mechanism

' This is not required if you send other output to the printer

' Object before outputting the image.

Printer.Print " "

ImageControl1.PrnHDC = Printer.hDC

' Now set the size & placement of the image

ImageControl1.DstLeft = 1 * TWIPS

ImageControl1.DstTop = 1 * TWIPS

ImageControl1.DstRight = 3 * TWIPS

ImageControl1.DstBottom = 3 * TWIPS

' Send the image to the printer


' Finish the print job and eject the page



The above code prints the entire image. To print a portion of the image requires that the Src properties, SrcTop , SrcLeft, SrcRight, and SrcBottom be set to the portion of the image to be printed. These are specified in image coordinates. For instance, to print just the upper left quarter of the image, the properties would be set like this:


ImageControl1.SrcLeft = 0

ImageControl1.SrcTop = 0

ImageControl1.SrcRight = ImageControl1.ImageWidth / 2

ImageControl1.SrcBottom = ImageControl1.ImageHeight / 2


Multiple images can be printed on a page by loading the control with each image and outputting it before calling the Printer.EndDoc or Printer.NewPage methods.

If you are printing from an environment that does not have a printer object which exposes the printer device context (hdc), you can use the new printer methods: PrintStart , PrintNextPage and PrintEndDoc. The following code prints all the pages in a multi-page file using these properties.


Dim nPage As Integer

nPage = 0

ImageControl1.PrintStart True ' Show printer selection dialog.


ImageControl1.PageNumber = nPage

' This code makes possibly wrong assumptions about

' Page Size, Image Size, and Printer Format.

ImageControl1.DstLeft = 0

ImageControl1.DstTop = 0

ImageControl1.DstRight = 1440 * 8.5

ImageControl1.DstBottom = 1440 * 11


nPage = nPage + 1

If npage < ImageControl1.Pages THEN


End If

Loop While nPage < ImageControl1.Pages



When printing multiple images it may be desirable to make the image control invisible to prevent the display of each image. This is done by setting the Visible property to False.



© 2014 Data Techniques, Inc. All rights reserved.

Submit feedback on this topic