Victor Image Processing Library How-to Tips

Print a Multipage TIFF File

The steps used to print a multipage document

Print a multipage TIFF file - the Visual Basic Source Code

Requires Victor Image Processing Library v 5.3 or higher.
' ........... Defines and declarations ...........

' Image descriptor
Type imgdes
   ibuff As Long
   stx As Long
   sty As Long
   endx As Long
   endy As Long
   buffwidth As Long
   palette As Long
   colors As Long
   imgtype As Long
   bmh As Long
   hBitmap As Long
End Type

    left As Long
    top As Long
    right As Long
    bottom As Long
End Type

Type TiffData
   ByteOrder As Long
   width As Long
   length As Long
   BitsPSample As Long
   comp As Long
   SamplesPPixel As Long
   PhotoInt As Long
   PlanarCfg As Long
   vbitcount As Long
End Type

Declare Function allocimage Lib "VIC32.DLL" (image As imgdes, ByVal wid As Long, ByVal leng As Long, ByVal bppixel As Long) As Long
Declare Sub freeimage Lib "VIC32.DLL" (image As imgdes)
Declare Function tiffgetpageinfo Lib "VIC32.DLL" (ByVal Fname As String, ByRef totalpages As Long, ByRef pagearray As Long, ByVal arrayelems As Long) As Long
Declare Function tiffinfopagebyindex Lib "VIC32.DLL" (ByVal Fname As String, tdat As TiffData, ByVal pageIndex As Long) As Long
Declare Function loadtifpagebyindex Lib "VIC32.DLL" (ByVal Fname As String, desimg As imgdes, ByVal pageIndex As Long) As Long
Declare Function printimage Lib "VIC32.DLL" (ByVal hWnd As Long, ByVal hdcprn As Long, ByVal mode As Long, image As imgdes, pRect As RECT, ByVal boxsiz As Long, ByVal dspfct As Long) As Long
Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

' ........... The function ...........
Private Sub mnutifmultipage_Click()
Dim rcode As Long
Dim tempimage As imgdes
Dim hdcprn As Long
Dim prtrect As RECT
Dim fileinfo As TiffData
Dim pagearray() As Long
Dim j As Long

' Determine number of pages in the file
rcode = tiffgetpageinfo("5pages.tif", maxpages, 0, 0)

If (rcode = NO_ERROR) Then
   ' For each page in the file
    For j = 0 To (maxpages - 1)

        ' Determine the image dimensions and pixel depth 
        rcode = tiffinfopagebyindex("5pages.tif", fileinfo, j)

        ' Allocate space for the image 
        rcode = allocimage(tempimage, fileinfo.width, fileinfo.length, fileinfo.vbitcount)
        If (rcode = NO_ERROR) Then
            ' Load the image    
            rcode = loadtifpagebyindex("5pages.tif", tempimage, j)

            ' Print the image    
            If (rcode = NO_ERROR) Then   ' Print 8 inches wide, adjust length to maintain aspect ratio
                rcode = SetRect(prtrect, 0, 0, 8000, 8000 * fileinfo.length / fileinfo.width)
                rcode = printimage(hWnd, Printer.hdc, 0, tempimage, prtrect, 0, 0)
            End If

            ' Free the image buffer 
            freeimage tempimage
        End If
    Next j  ' Go to the next page 
End If

End Sub

Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code

Copyright © 2002 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.