Victor Image Processing Library How-to Tips

Create a Document with Text and Graphic Images

Begin by initializing the printer, print each image, create the fonts for the text and print each block of text. Eject the page. The images and text are printed into rectanglular areas of the page. The image rectangle is specified in mils (1/1000s of an inch) and the text rectangle is specified in device pixels.

Print a document containing an image and text - the Source Code

This function prints an image in the upper left corner of the page and text in a column to the right of the image. The text is a NULL-terminated string of characters. Requires Victor Image Processing Library for Windows v 4.1x or higher.
int print_document(imgdes *srcimg, char far *text)
{
#define EJECTPAGE TRUE
#define FONT_FOR_DOCUMENT_SIZE 18
   static LOGFONT lf = { // Use font described by LOGFONT struct
      0, 0, 0, 0, FW_NORMAL, 0, 0, 0,
      ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
      DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "ARIAL"
      };
   HFONT hFont, hOldFont;
   HWND hwnd;
   HDC hdcprn;
   RECT prntrect; 
   int prtmode=0;
   int rcode = NO_ERROR, length;
   hwnd = GetActiveWindow();
   hdcprn = GetPrinterDC();    // Defined in VicDemo
            // Printing 3-inch wide image
   // prntrect: 0, 0, 2.999, [calculated length] inches
   // Use units of mils (1000 dpi) for prntrect for printing image
   length = srcimg->bmh->biHeight * 3000 / srcimg->bmh->biWidth;  // Maintain aspect ratio
   SetRect(&prntrect, 0, 0, 2999, length);
   printimagestartdoc(hdcprn, "Document containing image and text");
   rcode = printimagenoeject(hwnd, hdcprn, 0, srcimg, &prntrect, 0, (DLGPROC)NULL);
   // Use printer pixels as units for prntrect for printing text
   prntrect.left = GetDeviceCaps(hdcprn, LOGPIXELSX) * 3500 / 1000;   //3.5 inches
   prntrect.top = 0; 
   prntrect.right = GetDeviceCaps(hdcprn, HORZRES);
   prntrect.bottom = GetDeviceCaps(hdcprn, VERTRES);
             // Set the font point size
   lf.lfHeight= - MulDiv(FONT_FOR_DOCUMENT_SIZE, GetDeviceCaps(hdcprn, LOGPIXELSY), 72);
   hFont = CreateFontIndirect(&lf); // Create the font
   hOldFont = SelectObject(hdcprn, hFont); // Select font into DC
            // Print the text
   DrawText(hdcprn, text, -1, &prntrect, DT_LEFT | DT_WORDBREAK | DT_EXPANDTABS | DT_NOPREFIX);
   printimageenddoc(hdcprn, EJECTPAGE);
   DeleteObject(SelectObject(hdcprn, hOldFont));
   DeleteDC(hdcprn);
   return(rcode);
}

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


Victor Image Processing Library homepage | Victor Sample Code