|
I am using the Printer Object to print the image.
Here is my code. Pardon me if it is more then I should have posted....
Sub PrintSinglePage(PageNum%)
'Declare the variable for printed text Dim msg As String 'Declare the variables for pixel measurements Dim TextHeightInPixels Dim UsableWidth Dim UsableHeight
Dim lImageWidth1, lImageHeight1 As Long Dim WidthRatio1, HeightRatio1 Dim lStretchedWidth1, lStretchedHeight1 Dim ldblResolutionRatio1
frmViewer.ctlLeadEditor.ScaleMode = vbTwips Printer.ScaleMode = vbTwips UsableWidth = Printer.ScaleWidth UsableHeight = Printer.ScaleHeight
frmViewer.ctlLeadViewer.AutoRepaint = False
frmViewer.ctlLeadViewer.GetFileInfo TempImageFile, PageNum + 1, 0 frmViewer.ctlLeadViewer.LoadIFD = frmViewer.ctlLeadViewer.InfoIFD frmViewer.ctlLeadViewer.Load TempImageFile, 0, 1, 1 frmViewer.ctlLeadViewer.LoadIFD = 0
frmViewer.ctlLeadEditor.Bitmap = frmViewer.ctlLeadViewer.Bitmap 'Calculate image size ( in TWIPS ) If frmViewer.ctlLeadEditor.BitmapXRes >= frmViewer.ctlLeadEditor.BitmapYRes Then lImageWidth1 = frmViewer.ctlLeadEditor.BitmapWidth * (Printer.TwipsPerPixelX / Screen.TwipsPerPixelX) lImageHeight1 = (frmViewer.ctlLeadEditor.BitmapHeight * Printer.TwipsPerPixelX /Screen.TwipsPerPixelX)) * (frmViewer.ctlLeadEditor.BitmapXRes / frmViewer.ctlLeadEditor.BitmapYRes) Else lImageHeight1 = frmViewer.ctlLeadEditor.BitmapHeight * (Printer.TwipsPerPixelX / Screen.TwipsPerPixelX) lImageWidth1 = (frmViewer.ctlLeadEditor.BitmapWidth * (Printer.TwipsPerPixelX / Screen.TwipsPerPixelX)) * (frmViewer.ctlLeadEditor.BitmapYRes / frmViewer.ctlLeadEditor.BitmapXRes) End If
'Test values Printer.PrintQuality = GetDeviceCaps(Printer.hdc, LOGPIXELSX) If Printer.PrintQuality = 0 Or frmViewer.ctlLeadViewer.BitmapXRes = 0 Then MsgBox "Printer.PrintQuality = " & Printer.PrintQuality & vbCrLf _ & "frmViewer.ctlLeadViewer.BitmapXRes = " & frmViewer.ctlLeadViewer.BitmapXRes, vbOKOnly, "Zero value detected" Exit Sub End If ldblResolutionRatio1 = Printer.PrintQuality / frmViewer.ctlLeadViewer.BitmapXRes
'Test values If lImageWidth1 = 0 Or lImageHeight1 = 0 Or UsableWidth = 0 Or UsableHeight = 0 Then MsgBox "lImageWidth1 = " & lImageWidth1 & vbCrLf _ & "lImageHeight1 = " & lImageHeight1 & vbCrLf _ & "UsableWidth = " & UsableWidth & vbCrLf _ & "UsableHeight = " & UsableHeight, vbOKOnly, "Zero value detected" Exit Sub End If lImageWidth1 = lImageWidth1 * ldblResolutionRatio1 lImageHeight1 = lImageHeight1 * ldblResolutionRatio1 WidthRatio1 = (UsableWidth / lImageWidth1) 'in Pixels HeightRatio1 = (UsableHeight / lImageHeight1)
'Set the pointer to an hourglass Screen.MousePointer = 11
'Set Color Mode If frmViewer.ctlLeadEditor.BitmapBits = 1 Then Printer.ColorMode = 1 Else Printer.ColorMode = 2 End If
'Needed to open a print job Printer.Print 'Set EnlargeToPage = 0 for this test
EnlargeToPage = 0
If EnlargeToPage = 1 Then Printer.CurrentY = 0 If WidthRatio1 >= HeightRatio1 Then lStretchedHeight1 = UsableHeight lStretchedWidth1 = lStretchedHeight1 * (lImageWidth1 / lImageHeight1) Else lStretchedWidth1 = UsableWidth lStretchedHeight1 = lStretchedWidth1 * lImageHeight1 / lImageWidth1 End If Else lStretchedWidth1 = lImageWidth1 lStretchedHeight1 = lImageHeight1 If ((lStretchedWidth1 > UsableWidth) Or (lStretchedHeight1 > UsableHeight)) Then If (lStretchedWidth1 > UsableWidth) Then lStretchedWidth1 = UsableWidth lStretchedHeight1 = lStretchedWidth1 * (lImageHeight1 / lImageWidth1)
Else lStretchedHeight1 = UsableHeight lStretchedWidth1 = lStretchedHeight1 * (lImageWidth1 / lImageHeight1)
End If End If End If frmViewer.ctlLeadEditor.Render Printer.hdc, 0, 0, lStretchedWidth1, lStretchedHeight1
'Finish the page and finish the print job Printer.NewPage 'v2.21 moved to cmdOk:PrintDone 'Printer.EndDoc
'Set the mouse pointer back to the default Screen.MousePointer = 0
Exit Sub ErrorHandler: ' LogGlobalError MODULE_NAME, "PrintSinglePage", Err, Erl End Sub
Thanks.
Best regards,
Ken
|