Single and Multipage Printing

The BiPrint DLL or OCX contain the printing functions or methods. These methods can print device independent bitmaps with several options. You can display dialogs to change printing properties before printing.

 

[C++]

 

#include “BiPrint.h”

 

void CMyDoc::MyPrint()

{

         GPRINT  sPrint;

         DWORD     nPageCnt;

        

         // Set printig properties

         sPrint.bDisplay = 1;

         sPrint.bCenterVertImg = 0;

         sPrint.bCenterHorizImg = 0;

         sPrint.bScalePage = 1;

         sPrint.bUseDPI = 1;

         sPrint.nNumCopies = 1;

         sPrint.bConvertCtoB = 0;

         sPrint.bStretchPage = 0;

         sPrint.bAllPage = 1;

 

         // Prepares to print

         // 1. parameter (HWND): Handle to the window

         // 2. parameter (HDC): Printer DC. Can be NULL.

         // 3. parameter (LPGPRINT): Pointer to the print information structure

         // 4. parameter (LPSTR): Name of the file to print

         // 5. parameter (UINT): Number of pages in the document

         int ret = PrepareToPrint(AfxGetMainWnd()->m_hWnd, App->m_PrinterDC

                        ,&sPrint, szFileName, nImages);

 

         POINT ptDPI;

         LPPOINT lpPointDPI = NULL;

         LPBITMAPINFOHEADER lpbmi =

                        (LPBITMAPINFOHEADER)GlobalLock(hDib);

         if(lpbmi->biXPelsPerMeter && lpbmi->biYPelsPerMeter)

         {

            ptDPI.x = (int)( (float)lpbmi->biXPelsPerMeter / 39.37 + 0.5 );

            ptDPI.y = (int)( (float)lpbmi->biYPelsPerMeter / 39.37 + 0.5 );

            lpPointDPI = &ptDPI;

         }

         GlobalUnlock(hDib);

 

         if (!ret)

         {

            if(sPrint.bAllPage)

            {

                        for(nPageCnt = 0; nPageCnt < nImages; nPageCnt++)

                        {

                                    // Load specified page into DIB

                                    HDIB hDibTmp = LoadImage(szTiffFileName, nPageCnt);

                                    if (hDibTmp)

                                    {

                                                // 1. parameter: Handle of the DIB

                                                // 2. parameter: Image DPI

                                                // 3. parameter: Scaling factor

                                                // 4. parameter: Current Page number

                                                // 5. parameter: A positive absolute offset in pixel on the X

                                                //          coordinate on the page to start printing.

                                                // 6. parameter: A positive absolute offset in pixel on the Y

                                                //          coordinate on the page to start printing.

                                                PrintDIBPage(hDibTmp, lpPointDPI, &rScale, nPageCnt,

                                                            0, 0);

                                                …

                                                GlobalFree(hDibTmp);

                                    }

                        }

            }

            else

                        PrintDIBPage(hDib, lpPointDPI, &rScale, nCurPage,0,0);

         }

         EndPrint(NULL);

}

 

[VB]

 

Private Sub Print()

         Dim PrintObj As Object

         ReDim sRect(4) As Long

         Dim ret As Long

         Dim hDibTmp As Long

        

         Set PrintObj = CreateObject("BIPRINT.BIPrintCtrl.1")

         sRect(0) = 1

         sRect(1) = 1

         sRect(2) = 1

         sRect(3) = 1

 

         ‘ 1. parameter: Window handle for dialog boxes

         ‘2. parameter: Capture text to print

         ‘ 3. parameter: maximum page number

         ‘ 4. parameter: Number of copies

         ‘ 5. parameter: Display print dialog box

         ‘ 6. parameter: Center image vertically

         ‘ 7. parameter: Center image horizontally

         ‘ 8. parameter: Scale image to fit proportionally

         ‘ 9. parameter: Convert bitmap to monochrome

         ‘ 10. parameter: Stretch bitmap

         ‘ 11. parameter: All pages

         ‘ 12. parameter: Use DPI settings

         ‘ 13. parameter: Display or not cancel printing dialog box

         ret = PrintObj.PrepareToPrint(hWnd, ImageName$, MaxPage&, 1, False, False,

                        False, True, False, False, True, True, False)

 

         ‘ Print all pages from a multipage file

         For nPic = 0 To MaxPage – 1

            ‘ Load specified page into DIB

            hDibTmp = LoadImage(FileName, nPic)

            PrintObj.PrintDIBPage (hDibTmp, sRect(0), nPic, 0, 0)

            …

            BiDisp.DropDIB (hDibTmp)

         Next nPic

         PrintObj.EndPrint

 

         Set PrintObj = Nothing

End Sub

 

[C#]

 

private void Print()

{

            int hDib = BiDisp.hDib;

            int hwnd = BiDisp.hWnd;

            int[] sRect;

           

            sRect = new int[4];

            sRect[0] = 1;

            sRect[1] = 1;

            sRect[2] = 1;

            sRect[3] = 1;

           

            if (PrinterSettings.InstalledPrinters.Count > 0)

            {

                        // Print the actual DIB

                        if (hDib != 0)

                        {

                                    // 1. parameter: Window handle for dialog boxes

                                    // 2. parameter: Capture text to print

                                    // 3. parameter: maximum page number

                                    // 4. parameter: Number of copies

                                    // 5. parameter: Display print dialog box

                                    // 6. parameter: Center image vertically

                                    // 7. parameter: Center image horizontally

                                    // 8. parameter: Scale image to fit proportionally

                                    // 9. parameter: Convert bitmap to monochrome

                                    // 10. parameter: Stretch bitmap

                                    // 11. parameter: All pages

                                    // 12. parameter: Use DPI settings

                                    // 13. parameter: Display or not cancel printing dialog box

 

                                    BiPrint.PrepareToPrint(hwnd, GetDocument().szFileName,

                                    maxPage, 1, true, false, false, false, false, false, false, true, false);

                                    BiPrint.PrintDIBPage(hDib, ref sRect[0], 1, 0, 0);

                                    BiPrint.EndPrint();

                        }

            }

            else

            {

                        // Error

            }

         }