Print a file? send file to printer....
i have this wierd ms access project. The project is about retrieving .tif files from a database (stored path of .tif files) and present it for viewing in a imagebox. My problem is how to print the retrieved .tif file. We are not allowed to use a print common dialoge box. a click of a button is all that's needed to print the .tif file. Is there a way to print/send the .tif file to printer? Do I have to deal with the printer collection? Is this possible? (locate the file from the hard drive then send printer?)
Re: Print a file? send file to printer....
Change from using an Image control to using a Picturebox and use this to send the picture to print.
VB Code:
Private Sub PrintPictureToFitPage(Prn As Printer, Pic As Picture)
Dim PicRatio As Double
Dim PrnWidth As Double
Dim PrnHeight As Double
Dim PrnRatio As Double
Dim PrnPicWidth As Double
Dim PrnPicHeight As Double
Const vbHiMetric As Integer = 8 '
' Determine if picture should be printed in landscape
' or portrait and set the orientation.'
If Pic.Height >= Pic.Width Then
Prn.Orientation = vbPRORPortrait 'Taller than wide
Else
Prn.Orientation = vbPRORLandscape 'Wider than tall
End If '
' Calculate device independent Width to Height ratio for picture.'
PicRatio = Pic.Width / Pic.Height '
' Calculate the dimentions of the printable area in HiMetric.'
With Prn
PrnWidth = .ScaleX(.ScaleWidth, .ScaleMode, vbHiMetric)
PrnHeight = .ScaleY(.ScaleHeight, .ScaleMode, vbHiMetric)
End With '
' Calculate device independent Width to Height ratio for printer.'
PrnRatio = PrnWidth / PrnHeight '
' Scale the output to the printable area.'
If PicRatio >= PrnRatio Then '
' Scale picture to fit full width of printable area. '
PrnPicWidth = Prn.ScaleX(PrnWidth, vbHiMetric, Prn.ScaleMode)
PrnPicHeight = Prn.ScaleY(PrnWidth / PicRatio, vbHiMetric, Prn.ScaleMode)
Else
' Scale picture to fit full height of printable area. '
PrnPicHeight = Prn.ScaleY(PrnHeight, vbHiMetric, Prn.ScaleMode)
PrnPicWidth = Prn.ScaleX(PrnHeight * PicRatio, vbHiMetric, Prn.ScaleMode)
End If '
' Print the picture using the PaintPicture method.'
Call Prn.PaintPicture(Pic, 0, 0, PrnPicWidth, PrnPicHeight)
End Sub
Private Sub cmdPrintPicture_Click()
Call PrintPictureToFitPage(Printer, Picture1.Picture)
Printer.EndDoc
End Sub
Re: Print a file? send file to printer....
thank you very much for this. i will apply this to vb coz i cant find the picture box control in access. thanks a lot.