FILE: PRTLGPCT.EXE: Print a Large Bitmap on Multiple Pages

Last reviewed: November 11, 1997
Article ID: Q175084
The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0

SUMMARY

The PaintPicture method of the Picture object allows you to print the picture. However, this method will adjust the picture size to fit on a single sheet of paper. This article shows you how to print a large picture on multiple sheets of paper.

A sample project demonstrating printing a large picture on multiple sheets is available for download from the Microsoft Software Library:

 ~ Prtlgpct.exe (size: 25983 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

When you run the self-extracting file, the following files are expanded into the Printing Large Pictures Project on your hard drive:
  • <File list will be compiled after tech review> <filesize> bytes

MORE INFORMATION

To print a large picture over several sheets, you start by calculating the ratio of the picture's height and width to the maximum height and width the printer can print. From this ratio, you can calculate the number of pages required to print the picture completely. With each page, you use the PrintPicture method to print the maximum image on that sheet. Keep repeating this process on each successive page until the picture is completely printed.

The next section shows you how to create a sample program to demonstrate this technique.

Step-by-Step Example

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add three CommandButtons, a Common Dialog control, and a Picture control to Form1.

  3. Copy the following code to the Code window of Form1:

          Option Explicit
    

          Const constMaxValue = 32767
    

          Dim lngPrinterWidth As Long, lngPrinterHeight As Long
          Dim lngPictureWidth As Long, lngPictureHeight As Long
          Dim lngXCoor As Long, lngYCoor As Long
          Dim sngWidthRatio As Single, sngHeightRatio As Single
          Dim intPageWidth As Integer, intPageHeight As Integer
          Dim bytWidthCount As Byte, bytHeightCount As Byte
    

          Private Sub Form_Load()
    
             Command1.Caption = "Load Picture"
             Command2.Caption = "Print Single Page"
             Command3.Caption = "Print Multiple Pages"
          End Sub
    
          Private Sub Command1_Click()
             'Opens the common dialog box so you can select a picture file
             'to load into the Picture object.
             Dim picFile As Picture
             CommonDialog1.Filter = "JPEG files|*.jpg|BMP files|*.bmp"
             CommonDialog1.ShowOpen
    
             If CommonDialog1.filename <> "" Then
                Set picFile = LoadPicture(CommonDialog1.filename)
                Set Picture1.Picture = picFile
                Form1.Height = Picture1.Height + 1700
                Form1.Width = Picture1.Width + 1400
                Picture1.Left = 700
                Picture1.Top = 700
             End If
          End Sub
    
          Private Sub Command2_Click()
             'Print the picture on a single sheet. Picture object automatically
             'adjusts picture size to fit into a single sheet.
             Printer.PaintPicture Picture1.Picture, lngXCoor, lngYCoor
             Printer.EndDoc
             MsgBox "Done Sending Info to Printer"
          End Sub
    
          Private Sub Command3_Click()
             'Print the picture on multiple sheets.
    
             'Load the dimensions of the image and printer into memory
             lngPictureWidth = Picture1.Picture.Width
             lngPictureHeight = Picture1.Picture.Height
             lngPrinterWidth = Printer.Width
             lngPrinterHeight = Printer.Height
    
             'Calculate the ratios
             sngWidthRatio = lngPictureWidth / lngPrinterWidth
             sngHeightRatio = lngPictureHeight / lngPrinterHeight
    
             'Calculate how many pages are required to print the picture
             intPageWidth = constMaxValue - Int(constMaxValue - sngWidthRatio)
             intPageHeight = constMaxValue - Int(constMaxValue - _
                                                             sngHeightRatio)
    
             For bytWidthCount = 1 To intPageWidth
    
                'Calculate the x-offset
                lngXCoor = -lngPrinterWidth * (bytWidthCount - 1)
    
                For bytHeightCount = 1 To intPageHeight
    
                'Calculate the y-offset
                   lngYCoor = -lngPrinterHeight * (bytHeightCount - 1)
    
                   'Use the Paint Picture method to print the picture
                   Printer.PaintPicture Picture1.Picture, _
                                        lngXCoor, _
                                        lngYCoor, _
                                        lngPictureWidth, _
                                        lngPictureHeight
                   'start a new page
                   Printer.NewPage
                Next bytHeightCount
             Next bytWidthCount
    
             Printer.EndDoc
             MsgBox "Done Sending Info to Printer"
          End Sub
    
    

  4. Press the F5 key to run the program. Click Load Picture to open the Common Dialog, and choose a picture file. Click Print Single Page to print the picture to a single page or Print Multiple Pages to print to multiple pages.
Keywords          : vb432 VB4WIN vb5all VBKBPrinting
Version           : WINDOWS:4.0,5.0
Platform          : WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 11, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.