Copyright © 1989-2010 by Joe C. Hecht All Rights Reserved
Copyright © 2011-2019 by CODE4SALE, LLC All Rights Reserved
Contact CODE4SALE, LLC - Joe Hecht.
TExcellent home page
TExcellent documentation home page!
Try TExcellentFormPrinter!
Buy TExcellentFormPrinter!
Try TExcellentImagePrinter!
Buy TExcellentImagePrinter!
Product names, trademarks, and servicemarks mentioned are owned by their respective owners.
Changes since version 3.4
All TExcellent products have now been upgraded to be compatible with all 32 and 64 bit versions of the
Delphi and C++ Builder Windows compilers, and the TExcellent version number has been adjusted to now reflect
compatibility with RAD Studio compiler version numbers.
Please note that TExcellentFormPrinter and the PrnUtils dialog are very VCL specific.
Non VCL notes: While TExcellent products are VCL and Windows specific, and FireMonkey is not officially supported,
we have found that some TExcellent products are in fact usable in non-VCL projects. For example, TExcellentImagePrinter
can be used in a FireMonkey Windows application (complete with the PrnUtils abort dialog) with minimal changes to your
calling code. For example, creating our printing abort / status dialog can be accomplished with the following code:
C++Builder:
AbortDialog := CreateAbortDialog(FMX.Platform.Win.FormToHWND(this), this);Delphi:
AbortDialog := CreateAbortDialog(FMX.Platform.Win.FormToHWND(self), self);
TExcellentCompilerDefs.inc: Not required by the TExcellent products themselves.
The example and demo projects now make use of an include file to help determine the compiler version and capabilities in use, and is
PrnDibBuildMode.inc: An include file used to determine the build mode (Currently demo/release) and
is required to compile release (non-demo) versions of TExcellent products.
Some Types have been renamed to reflect the name of the unit they are used in (to avoid scoping and compiler errors,
and to allow the C and Pascal source to have greater symmetry).
Pointer types traditionally passed to callback functions as typecast integer values have been typed to a pointer sized
integer (size_t where practical and a 32 unsigned integer where not practical) and renamed as follows:
UNITNAME_PTR_UINT
UNITNAME_PTR_AS_UINT
Example:
PRNFORM_PTR_AS_UINT
PRNFORM_PTR_UINT
TAppCallbackFn() has been renamed to:
TPrnFormAppCallbackFn (TExcellentFormPrinter)
TPrnDibAppCallbackFn (TExcellentImagePrinter)
Pointers to character strings used in filenames and captions hsve changed to TCaption and TFilename types!
In some cases, pointers to untyped pointer types (void *) have changed to (PVOID *).
Version 0A.3.1 change: if (__BORLANDC__ >= 0x740) Win32Platform becomes a function call to Win32Platform().
Installation
PrintDIBitmap
PrintDIBitmapXY
PrintDIBitmapCB
PrintDIBitmapEx
PrnDIBSetDebugMsg
PrnDIBSetAbortDialogHandle
PrnDIBSetDebugBlt
PrnDIBSetDebugBltCode
PrnDIBSetDebugUseDDB
PrnDIBSetDebugAutoUseDDB
PrnDIBSetDebugFrames
PrnDIBSetSleepValue
PrnDIBSetDebugPaletteNone
PrnDIBSetDebugPaletteForce
PrnDIBSetDebugPaletteNotAllowed
PrnDIBSetDebugDcSaves
PrnDIBSetDebugGdiFlush
PrnDIBSetOutputScaleFactor
PrnDIBSetDoWinScale
If you are using the trail version of TExcellentImagePrinter, to compile the units into your project, you will need to:
1) unzip the .obj and .dfm files and place them in your project directory.
2) If you are not using CBuilder 5, go to the BCB menu, and select Project->Add to Project, and select the PrnUtils.obj and PrnDib.obj files.
3) Add the following #include and #pragma statements to the unit that you are using TExcellentImagePrinter from:
#include "Printers.hpp"
#include "PrnUtils.h"
#include "PrnDib.h"
#pragma link "PrnUtils"
#pragma link "PrnDib"
If you are using the registered version of TExcellentImagePrinter, to compile the units into your project, you will need to:
1) unzip the .cpp, .h, and .dfm files and place them in a directory that has a common path with your other CBuilder components. Delete any trial version .dfm, .h, and .obj files you might have installed.Back to Functions and Structures
int __stdcall PrintDIBitmap(HDC dc, BITMAPINFO * lpBitmapInfo, void * lpBits, BOOL Centered, BOOL UsePerfectMargins);
Location: PrnDib.h and PrnDib.cpp
Images a Device Independent Bitmap onto dc (Canvas.Handle). Stretches
the image proportionally to fit the device. The lpBitmapInfo parameter
is a pointer to a BitmapInfo or a BitmapCoreInfo structure. The lpBits
paramter is a pointer to the DIB bits. If Centered is TRUE, then the
printout will be centered on the device, else the printout will start at the
top left corner of the device. If UsePerfectMargins is TRUE, then the
print margin will be adjusted to accomodate devices that have uneven page
margins. It is recommended that you use one of the LoadDIB() functions contained
in our PrnUtils unit to get your BitmapInfo
and DIB bits pointers.
Returns:
#define PRINT_SUCCESSFUL 1
#define NOTHING_TO_PRINT 0
#define BAD_PARAMETER -1
#define MEMORY_ALLOC_FAILED -2
#define MEMORY_READ_FAILED -3
#define MEMORY_WRITE_FAILED -4
#define USER_ABORT_OR_OTHER_ERROR -5
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
int __stdcall PrintDIBitmapXY(HDC dc, int dstx, int dsty, int dstWidth, int dstHeight, BITMAPINFO * lpBitmapInfo, void * lpBits);
Location: PrnDib.h and PrnDib.cpp
Images a Device Independent Bitmap onto dc (Canvas.Handle) at
dstx, dsty, and stretches the image to dstWidth, dstHeight. The
lpBitmapInfo parameter is a pointer to a BitmapInfo or a BitmapCoreInfo
structure. The lpBits parameter is a pointer to the DIB bits. It is
recommended that you use one of the LoadDIB() functions contained in our
PrnUtils unit to get your BitmapInfo and
DIB bits pointers.
Returns:
#define PRINT_SUCCESSFUL 1
#define NOTHING_TO_PRINT 0
#define BAD_PARAMETER -1
#define MEMORY_ALLOC_FAILED -2
#define MEMORY_READ_FAILED -3
#define MEMORY_WRITE_FAILED -4
#define USER_ABORT_OR_OTHER_ERROR -5
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrintDIBitmapXY(Printer()->Canvas->Handle, 0, 0, BitmapWidth, BitmapHeight, BitmapInfo, Bits); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
int __stdcall PrintDIBitmapCB(HDC dc, BITMAPINFO * lpBitmapInfo, void * lpBits, BOOL Centered, BOOL UsePerfectMargins, TPrnDibAppCallbackFn OnAppCallbackFn, PRNDIB_PTR_AS_UINT OnAppCallbackData);
Location: PrnDib.h and PrnDib.cpp
Images a Device Independent Bitmap onto dc (Canvas.Handle). Stretches the image proportionally to fit the device. The lpBitmapInfo parameter is a pointer to a BitmapInfo or a BitmapCoreInfo structure. The lpBits parameter is a pointer to the DIB bits. If Centered is TRUE, then the printout will be centered on the device, else the printout will start at the top left corner of the device. If UsePerfectMargins is TRUE, then the print margin will be adjusted to accommodate devices that have uneven page margins. The OnAppCallbackFn is an optional callback function that you may install to track the progess of the imaging and optionally provide real time status updates to your user (perhaps by using a progress meter) as well as allowing you to cancel the imaging job. If you do not install a callback function, simply pass nil in this parameter. If you do install a callback function, you would pass the address of your callback function, and during the image job, you will be passed the original value you passed in the OnAppCallbackData parameter each time your callback function is called. If you do not install a callback function, you simply pass zero in the OnAppCallbackData parameter. The callback function is passed the number of "UnitsDone" (the amount completed), the "TotalUnits" (the total number of units that will be processed) and the OnAppCallbackData that you originally passed to the PrintDIBitmapEx() function. Note that while the OnAppCallbackData parameter is prototyped as a pointer sized unsigned integer, any pointer sized value can be passed by using typecasting. In other words, you could pass a pointer or object reference (such as a form reference or a reference to a TMemo) by using typecasting. This is demonstrated in the example given below. Note that this callback function may be called several times with the same value for "UnitsDone". Please also note that this is a pure stand alone callback function and not a TEvent or a method. The prototype for the callback function looks like this:
BOOL __stdcall AppPrintingCallbackFn(DWORD UnitsDone, DWORD TotalUnits, PRNDIB_PTR_AS_UINT UserData) { //Return TRUE to continue the printjob or FALSE to abort the printjob return(TRUE); }
It is recommended that you use one of the LoadDIB() functions contained
in our PrnUtils unit to get your BitmapInfo
and DIB bits pointers.
Returns:
#define PRINT_SUCCESSFUL 1
#define NOTHING_TO_PRINT 0
#define BAD_PARAMETER -1
#define MEMORY_ALLOC_FAILED -2
#define MEMORY_READ_FAILED -3
#define MEMORY_WRITE_FAILED -4
#define USER_ABORT_OR_OTHER_ERROR -5
Example:
//--------------------------------------------------------------------------- //-- A callback function for updating an image printer abort dialog! -------- //--------------------------------------------------------------------------- BOOL __stdcall ImagePrinterCallbackFunction(DWORD UnitsDone, DWORD TotalUnits, TAbortDialog * AbortDialog) { System::AnsiString s; // Update the abort dialogs caption to give a status update s = "Printing - " + IntToStr(INT((((float)UnitsDone / (float)TotalUnits) * 100))) + "%"; AbortDialogSetCaption(AbortDialog, s.c_str()); // Return if the user has canceled the print job. return(! AbortDialogUserHasCanceled(AbortDialog)); } //--------------------------------------------------------------------------- //-- Print test.bmp scaled to a full page - with abort dialog! -------------- //--------------------------------------------------------------------------- void __fastcall TForm1::PrintImageClick(TObject *Sender) { TAbortDialog *AbortDialog; // The abort dialog BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); // Create the abort dialog AbortDialog = CreateAbortDialog(Application->Handle, this); PrnDIBSetAbortDialogHandle(AbortDialog->Handle); PrintDIBitmapCB(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE, (TPrnDibAppCallbackFn)ImagePrinterCallbackFunction, (PRNDIB_PTR_AS_UINT)AbortDialog); FreeAbortDialog(AbortDialog); PrnDIBSetAbortDialogHandle(0); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
int __stdcall PrintDIBitmapEx(HDC dc, int dstx, int dsty, int dstWidth, int dstHeight, int srcx, int srcy, int srcWidth, int srcHeight, BITMAPINFO * lpBitmapInfo, void * lpBits, HPALETTE Palette, BOOL ForcePalette, BOOL DoNotUsePalette, RECT * DeviceClipRect, TPrnDibAppCallbackFn OnAppCallbackFn, PRNDIB_PTR_AS_UINT OnAppCallbackData);
Location: PrnDib.h and PrnDib.cpp
Images a Device Independent Bitmap onto dc (Canvas.Handle) at dstx, dsty, and stretches the image to dstWidth, dstHeight. srcx is horizontal position in the image to start the printout and srcy is the vertical position in the image to start the printout. srcWidth is the horizontal width of the source image to print, and srcHeight is the vertical height of the source image to print. NOTE: (srcx + srcWidth) or (srcy + srcHeight) cannot exceed the bitmap size, and srcx and srcy may not be negative. The lpBitmapInfo parameter is a pointer to a BitmapInfo or a BitmapCoreInfo structure. The lpBits parameter is a pointer to the DIB bits. It is recommended that you use one of the LoadDIB() functions contained in our PrnUtils unit to get your BitmapInfo and DIB bits pointers. Palette is an optional handle to a windows palette. If the palette is zero, and the device is a palette device, then TExcellentImagePrinter will attempt to create a palette in your behalf automatically and select it into the device context. ForcePalette is the value passed to the Windows SelectPalette() function. DoNotUsePalette is a boolean value used to disable palette handling. If this parameter is set to TRUE, then you are responsible for selecting and realizing the palette (if any) for the dc before and after the function call. In this case,you should set the Palette parameter to zero, and the ForcePalette parameter will be ignored. The DeviceClipRect parameter specifies the area of the device to clip output to, and should be no larger than the device surface. The DeviceClipRect parameter is useful in stretching the output to span across multiple pages (up to 2 billion pixels high and wide), and allows the Print engine to optimize output by processing only the stretched data contained in the ClipRect area. This also allows the engine to overcome Windows 9x GDI limitations of a 32000 pixel high/wide output. The OnAppCallbackFn is an optional callback function that you may install to track the progess of the imaging and optionally provide real time status updates to your user (perhaps by using a progress meter) as well as allowing you to cancel the imaging job. If you do not install a callback function, simply pass nil in this parameter. If you do install a callback function, you would pass the address of your callback function, and during the image job, you will be passed the original value you passed in the OnAppCallbackData parameter each time your callback function is called. If you do not install a callback function, you simply pass zero in the OnAppCallbackData parameter. The callback function is passed the number of "UnitsDone" (the amount completed), the "TotalUnits" (the total number of units that will be processed) and the OnAppCallbackData that you originally passed to the PrintDIBitmapEx() function. Note that while the OnAppCallbackData parameter is prototyped as a pointer sized unsigned integer, any pointer sized value can be passed by using typecasting. In other words, you could pass a pointer or object reference (such as a form reference or a reference to a TMemo) by using typecasting. This is demonstrated in the example given below. Note that this callback function may be called several times with the same value for "UnitsDone". Please also note that this is a pure stand alone callback function and not a TEvent or a method. The prototype for the callback function looks like this:
BOOL __stdcall AppPrintingCallbackFn(DWORD UnitsDone, DWORD TotalUnits, PRNDIB_PTR_AS_UINT UserData) { //Return TRUE to continue the printjob or FALSE to abort the printjob return(TRUE); }
Returns:
#define PRINT_SUCCESSFUL 1
#define NOTHING_TO_PRINT 0
#define BAD_PARAMETER -1
#define MEMORY_ALLOC_FAILED -2
#define MEMORY_READ_FAILED -3
#define MEMORY_WRITE_FAILED -4
#define USER_ABORT_OR_OTHER_ERROR -5
Example:
Note: This is a complex print bitmap example - uses default printer, allows for centering on page, perfect even margines, scaling the image *very large* to span multiple pages across and down, and provides a status/abort dialog using the optional callback function. The number of pages to span is hardcoded in the main function, and the image is scaled proportionally to fit the printout.
//--------------------------------------------------------------------------- //define a data type we will use during a callback //to update an abort dialog with a status update #pragma pack(push, 1) typedef struct _AppCallbackData { TAbortDialog * AbortDialog; //The abort dialog int PageAcross; //The current page printing across int PageDown; //The current page printing down } TAppCallbackData, *PAppCallbackData; #pragma pack(pop) //--------------------------------------------------------------------------- //Our optional status update callback event BOOL __stdcall AppPrintingCallbackFn(DWORD UnitsDone, DWORD TotalUnits, PRNDIB_PTR_AS_UINT UserData) { System::AnsiString s; TAppCallbackData * TheData; //cast UserData to a usable form TheData = (TAppCallbackData *) UserData; //update the abort dialogs caption to give a status update. s = "Printing Page " + IntToStr(TheData->PageAcross) + ":" + IntToStr(TheData->PageDown) + " - " + IntToStr(INT((((float)UnitsDone / (float)TotalUnits) * 100))) + "%"; AbortDialogSetCaption(TheData->AbortDialog, s.c_str()); //return if the user has canceled the print job. return(! AbortDialogUserHasCanceled(TheData->AbortDialog)); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { BITMAPINFO * BitmapInfo; //pointer to the BitmapInfo structure void * Bits; //pointer to the bits int BitmapWidth; //bitmap width int BitmapHeight; //bitmap height int ReturnValue; //value returned from PrintDIBitmapEx. int PagesWide; //How many pages wide you want. int PagesHigh; //How many pages high you want. BOOL CenterFormOnPage; //Center on the page or print at the top left corner? TAbortDialog* AbortDialog; //The Abort Dialog. TAppCallbackData AppCallbackData; //Our callback data structure. TPrnPageInfo PrnPageInfo; //Info about the page to be printed. int TotalImageWidth; //Total width of the printout (including multiple pages). int TotalImageHeight; //Total height of the printout (including multiple pages). double ScaleX; //How much the form gets stretched in the x direction. double ScaleY; //How much the form gets stretched in the y direction. int PrintedImageWidth; //Total printed width (including multiple pages). int PrintedImageHeight; //Total printed height (including multiple pages). POINT PrintedImageOffset; //How much to offset the image to print it centered on the page(s). int i; //Loop variable (for i := 1 to PagesHigh do). int j; //Loop variable (for j := 1 to PagesWide do). int SaveIndex; //Used to save the state of the printer. System::AnsiString APageCaption; //Used to print a caption on the page. System::AnsiString AnAbortCaption; //Used to update the abort dialog caption. RECT PageRect; //The clipping rectangle for the page. //how many pages to print across and down PagesWide = 2; PagesHigh = 2; //center the output on the page? (FALSE prints the form at the top left of the page). CenterFormOnPage = TRUE; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bad Load"); return; } //Note: we are done with configurable print choices! //disable the window so the user cannot click on anything while we are printing. EnableWindow(this->Handle, FALSE); //try to fire up the printjob! try { Printer()->BeginDoc(); } catch ( ... ) { //error! clean up and bail out! FreeMemEx(BitmapInfo); FreeMemEx(Bits); EnableWindow(this->Handle, TRUE); ShowMessage("Printer corrupt or not installed!"); return; } //create our abort dialog AbortDialog = CreateAbortDialog(Application->Handle, this); //Set our callback information AppCallbackData.AbortDialog = AbortDialog; //get the page information GetPrnPageInfo(Printer()->Canvas->Handle, &PrnPageInfo); // do some calculations to stretch and position // the form to fit the page (or pages). PageRect.left = 0; PageRect.top = 0; PageRect.right = PrnPageInfo.AdjustedPageArea.x; PageRect.bottom = PrnPageInfo.AdjustedPageArea.y; TotalImageWidth = PagesWide * PrnPageInfo.AdjustedPageArea.x; TotalImageHeight = PagesHigh * PrnPageInfo.AdjustedPageArea.y; ScaleX = (double)TotalImageWidth / (double)BitmapWidth; ScaleY = (double)TotalImageHeight / (double)BitmapHeight; if (ScaleX < ScaleY) { PrintedImageWidth = TotalImageWidth; PrintedImageHeight = BitmapHeight * ScaleX; PrintedImageOffset.x = 0; PrintedImageOffset.y = (TotalImageHeight / 2) - (PrintedImageHeight / 2); } else { PrintedImageHeight = TotalImageHeight; PrintedImageWidth = BitmapWidth * ScaleY; PrintedImageOffset.x = (TotalImageWidth / 2) - (PrintedImageWidth / 2); PrintedImageOffset.y = 0; } if (! CenterFormOnPage) { PrintedImageOffset.x = 0; PrintedImageOffset.y = 0; } //loop through and print the pages! for (i = 1; i <= PagesHigh; i++) { for (j = 1; j <= PagesWide; j++) { //set our callback information AppCallbackData.PageAcross = j; AppCallbackData.PageDown = i; //construct a caption to print at the top of each page. APageCaption = "Page " + IntToStr(j) + " : " + IntToStr(i); //construct a caption for the abort dialog. AnAbortCaption = "Printing " + APageCaption; //set the abort dialog's caption to give the user a status update AbortDialogSetCaption(AbortDialog, AnAbortCaption.c_str()); //test to see if the user canceled the print job if (AbortDialogUserHasCanceled(AbortDialog)) { //user canceled the print job - clean up and bail out! FreeMemEx(BitmapInfo); FreeMemEx(Bits); Printer()->Abort(); FreeAbortDialog(AbortDialog); EnableWindow(this->Handle, TRUE); ShowMessage("Printing Aborted!"); return; } //save the printer state SaveIndex = SaveDC(Printer()->Canvas->Handle); //move our origin to account for a perfect printing margin MoveWindowOrg(Printer()->Canvas->Handle, PrnPageInfo.AdjustedMarginOffset.x, PrnPageInfo.AdjustedMarginOffset.y); //allow drawing only within our prefect margins IntersectClipRect(Printer()->Canvas->Handle, 0, 0, PrnPageInfo.AdjustedPageArea.x, PrnPageInfo.AdjustedPageArea.y); //print the image! We will need to "back up" the offset of where we print //the image to account for printing across multiple pages. No need to fear, //TExcellentImage will allow us to print up to 2 billion pixels high //and wide, even under Windows 95 and 98! ReturnValue = PrintDIBitmapEx(Printer()->Canvas->Handle, -((j - 1) * PrnPageInfo.AdjustedPageArea.x) + PrintedImageOffset.x, -((i - 1) * PrnPageInfo.AdjustedPageArea.y) + PrintedImageOffset.y, PrintedImageWidth, PrintedImageHeight, 0, 0, BitmapWidth, BitmapHeight, BitmapInfo, Bits, 0, TRUE, FALSE, &PageRect, (TPrnDibAppCallbackFn)AppPrintingCallbackFn, (PRNDIB_PTR_AS_UINT)&AppCallbackData); if (ReturnValue < NOTHING_TO_PRINT) { //This will happen if the user has canceled the print job //or an error occured. We will not trap the NOTHING_TO_PRINT //error, as when the image is stretched across several pages, it //is possible that a few pages many not contain part of the image //due to page and image centering, and TExcellentImage printer will //report there is nothing to print for those pages. If we have another //kind of error then we will clean up and bail out! RestoreDC(Printer()->Canvas->Handle, SaveIndex); FreeAbortDialog(AbortDialog); Printer()->Abort(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); EnableWindow(this->Handle, TRUE); switch (ReturnValue) { case BAD_PARAMETER : ShowMessage("BAD_PARAMETER"); break; case MEMORY_ALLOC_FAILED : ShowMessage("MEMORY_ALLOC_FAILED"); break; case MEMORY_READ_FAILED : ShowMessage("MEMORY_READ_FAILED"); break; case MEMORY_WRITE_FAILED : ShowMessage("MEMORY_WRITE_FAILED"); break; case USER_ABORT_OR_OTHER_ERROR : ShowMessage("USER_ABORT_OR_OTHER_ERROR!"); break; } return; } //we can print those lovely page captions here (or anything else we care to print)! Printer()->Canvas->Font->Name = "Arial"; //fix a VCL issue that pops up sometimes with font scaling! Printer()->Canvas->Font->PixelsPerInch = PrnPageInfo.DPI.y; Printer()->Canvas->Font->Size = 10; Printer()->Canvas->TextOut(0, 0, APageCaption.c_str()); //we are done printing on this page, restore the printer state! RestoreDC(Printer()->Canvas->Handle, SaveIndex); //if not the last page, we need to call NewPage! if (! ((j == PagesWide) && (i == PagesHigh))) { Printer()->NewPage(); } } } //We are done! Time to clean up! FreeAbortDialog(AbortDialog); FreeMemEx(BitmapInfo); FreeMemEx(Bits); Printer()->EndDoc(); EnableWindow(this->Handle, TRUE); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugMsg(BOOL value);
Location: PrnDib.h and PrnDib.cpp
This function (when set to TRUE) causes a Windows messagebox
to be displayed in the event that the Windows StretchDIBits,
BitBlt, MoveTo, or LineTo functions fail. Should you use this
function, you should also call the
PrnDIBSetAbortDialogHandle()
to set the parent window of any messageboxes that are displayed,
else the messageboxs may not appear on the screen, but may in fact
show up on the taskbar. Should any messageboxes appear, this indicates
that the problem is most likely downstream from TExcellentImagePrinter,
but can be also caused by memory corruption in the VCL or your application,
especially in multi-threaded applications.
The default value is FALSE.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugMsg(TRUE); PrnDIBSetAbortDialogHandle(this->Handle); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
HWND __fastcall PrnDIBSetAbortDialogHandle(HWND value);
Location: PrnDib.h and PrnDib.cpp
This function informs the TExcellentImagePrinter engine of the handle
of a status windows you may be displaying during the print job, allowing
any error messageboxes to display on top of your status window. Failure
to set this value may cause any error messageboxes to be shown with the
Windows desktop as the owner.
This value only has meaning when
PrnDIBSetDebugMsg() is set to TRUE.
The default value is 0.
Returns:
The previous window handle.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugMsg(TRUE); PrnDIBSetAbortDialogHandle(this->Handle); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugBlt(BOOL value);
Location: PrnDib.h and PrnDib.cpp
This function (when set to FALSE) causes
TExcellentImagePrinter to go through its normal code
except it does not actually transfer the bitmap
to the GDI (ie, you will get a blank sheet of paper,
unless the PrnDIBSetDebugFrames
is set to TRUE.
If you get a crash in the TExcellentImagePrinter unit
in a simple test app, then it is likely you have exposed a
problem in the TExcellentImagePrinter code. Please
alert us as soon as possible so that we may
take steps to correct the problem and publish a fix (if
it can be determined that TExcellentImagePrinter actually
caused the problem).
At this point, you should also test the program in question
using the PrnDIBSetDebugBltCode
function to futher qualify where the problem might be.
The default value is TRUE.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugBlt(FALSE); PrnDIBSetDebugFrames(TRUE); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugBltCode(BOOL value);
Location: PrnDib.h and PrnDib.cpp
This function (when set to FALSE) causes
TExcellentImagePrinter to totally skip its normal
code in preparing to output a bitmap chunk. Further, it does not transfer
the bitmap to the GDI (ie, you will get a blank sheet of paper,
unless the PrnDIBSetDebugFrames
is set to TRUE.
If you get a crash in the TExcellentImagePrinter unit
in a simple test app, then it is likely you have exposed a
problem in the TExcellentImagePrinter code. Please
alert us as soon as possible so that we may
take steps to correct the problem and publish a fix (if
it can be determined that TExcellentImagePrinter actually
caused the problem).
The default value is TRUE.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugBltCode(FALSE); PrnDIBSetDebugFrames(TRUE); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugUseDDB(BOOL value);
Location: PrnDib.h and PrnDib.cpp
This function (when set to TRUE) causes
TExcellentImagePrinter to internally use a Device Dependent Bitmap
(as opposed to Device Independent Bitmap), and transfer
the bitmap using the Windows API function BitBlt(),
(as opposed to using the Windows API function StretchDIBits().
Please note that if a call to StretchDIBits() fails, the TExcellentImagePrinter
default recovery plan is to switch to using device dependent bitmaps
and transfer the bitmap using the Windows API function BitBlt(). This
automatic recovery logic can be controlled by the use of the
PrnDIBSetDebugAutoUseDDB()
function. A word of warning: Some printers will claim that StretchDIBits()
was successfull, even though the call actually failed. For those
printers, your application should still provide a way for the user
to force the use of device dependent bitmaps using a call to
the PrnDIBSetDebugUseDDB() function.
We have found that some printers report that they support
the Windows StretchDIBits() function, however, calls to the
StretchDIBits() functon will sometimes fail on some printers.
This function provides a workaround for buggy print drivers.
Note that for printers that do not support the Windows
StretchDIBits() function, it is still safe to call the
StretchDIBits() function, as Windows should automatically
simulate the call using lower level driver calls.
Note that the Device Dependent Bitmap that is created is
based on the context of the output device. This implies
that the bitmap created will most likely be a monochrome
bitmap with one bit of color depth. Note that most devices
do not provide for reasonable dithering of colors to a
monochrome bitmap, so color translation may be lost.
The default value is FALSE.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugUseDDB(TRUE); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugAutoUseDDB(BOOL value);
Location: PrnDib.h and PrnDib.cpp
Normally, TExcellentImagePrinter uses Device Independent Bitmaps
and the Windows API function StretchDIBits() to transfer images.
This function (when set to TRUE) causes TExcellentImagePrinter
first try using Device Independent Bitmaps and the StretchDIBits()
function. If the StretchDIBits() functon fails, then TExcellentImagePrinter
will automatically switch to using device dependent bitmaps and attempt
to transfer bitmaps using the Windows API function BitBlt().
Please note that some printers will claim that StretchDIBits()
was successfull, even though the call actually failed. For those
printers, your application should provide a way for the user
to force the use of device dependent bitmaps using a call to
the PrnDIBSetDebugUseDDB()
function.
We have found that some printers report that they support
the Windows StretchDIBits() function, however, calls to the
StretchDIBits() functon will sometimes fail on some printers.
This function provides a workaround for buggy print drivers.
Note that for printers that do not support the Windows
StretchDIBits() function, it is still safe to call the
StretchDIBits() function, as Windows should automatically
simulate the call using lower level driver calls.
Note that the Device Dependent Bitmap that is created is
based on the context of the output device. This implies
that the bitmap created will most likely be a monochrome
bitmap with one bit of color depth. Note that most devices
do not provide for reasonable dithering of colors to a
monochrome bitmap, so color translation may be lost.
The default value is TRUE.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugAutoUseDDB(FALSE); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugFrames(BOOL value);
Location: PrnDib.h and PrnDib.cpp
This function (when set to TRUE) causes
TExcellentImagePrinter to print cross-hairs through
each "chunk" that is printed. This is useful
for testing where the image chunks would be printed, and is
often used with the
PrnDIBSetDebugBlt(FALSE)
setting for debugging purposes.
The default value is FALSE in the registered versions of the product,
and is automatically set to TRUE in the trial versions.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugFrames(TRUE); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetSleepValue(int value);
Location: PrnDib.h and PrnDib.cpp
This function (when set a value of zero or greater) causes
TExcellentImagePrinter call the Windows API function Sleep(value)
between each image transfer function, and may provide some relief
for buggy 3rd party spooler software that may be installed with
some printer drivers, by allowing the spooler to catch up with the
image data that is sent.
The default value is -1.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetSleepValue(1000); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugPaletteNone();
Location: PrnDib.h and PrnDib.cpp
TExcellentImagePrinter will attempt to use a passed in palette
or build and select a palette into the destination device for
you, if the device reports that it supports palettes.
Using this function sets TExcellentImagePrinter to
use default palette handeling behaviour. Generally,
most printers do not suppport the use of palettes,
and this setting is mainly for use when using
TExcellentImagePrinter to print to a Windows
memory dc.
Other related functions:
PrnDIBSetDebugPaletteForce
PrnDIBSetDebugPaletteNotAllowed
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugPaletteNone(); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugPaletteForce();
Location: PrnDib.h and PrnDib.cpp
TExcellentImagePrinter will attempt to use a passed in palette
or build and select a palette into the destination device for
you, if the device reports that it supports palettes.
Using this function sets TExcellentImagePrinter
to force the use of a palette. Generally,
most printers do not suppport the use of palettes,
and this setting is mainly for use when using
TExcellentImagePrinter to print to a Windows
memory dc.
Other related functions:
PrnDIBSetDebugPaletteNone
PrnDIBSetDebugPaletteNotAllowed
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugPaletteForce(); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
PrnDIBSetDebugPaletteNotAllowed
void __stdcall PrnDIBSetDebugPaletteNotAllowed();
Location: PrnDib.h and PrnDib.cpp
TExcellentImagePrinter will attempt to use a passed in palette
or build and select a palette into the destination device for
you, if the device reports that it supports palettes.
Using this function sets TExcellentImagePrinter
to completely disallow the use of palettes. Generally,
most printers do not suppport the use of palettes,
and this setting is mainly for use when using
TExcellentImagePrinter to print to a Windows
memory dc.
Other related functions:
PrnDIBSetDebugPaletteNone
PrnDIBSetDebugPaletteForce
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugPaletteNotAllowed(); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugDcSaves(BOOL value);
Location: PrnDib.h and PrnDib.cpp
TExcellentImagePrinter will attempt to use the Windows API
SaveDC() and RestoreDc() functions. It might be possible that
this call could fail. Setting this variable to FALSE
will cause TExcellentImagePrinter to disregard perfect margins
and centering, and will also cause TExcellentImagePrinter not
to use the SaveDc(), RestoreDc(), GetWindowOrgEx(), SetWindowOrgEx()
and IntersectClipRect() functions. Should setting this variable
to TRUE cause a failed print job to print, then it
would indicate a serious problem at the print driver level.
The default value is TRUE.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugDcSaves(FALSE); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDebugGdiFlush(BOOL value);
Location: PrnDib.h and PrnDib.cpp
TExcellentImagePrinter default behaviour is to use the Windows API
call GdiFlush(). Calling this function with a value of FALSE
will disable calls to GdiFlush(). Generally, setting this
variable is of little help unless you are using threads
to produce your print job.
The default value is TRUE.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDebugGdiFlush(FALSE); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetOutputScaleFactor(int x, int y);
Location: PrnDib.h and PrnDib.cpp
The TExcellentImagePrinter default behaviour is output images pre-scaled to the
full resolution of the printer. This can produce large print jobs.
This function reduces the resolution of the output by the scale
factor given, and asks the print driver to enlarge the output
by the same amount. In other words, a scale factor of 2 reduces
the resolution of the output by 2, and the print driver will
enlarge the output by 2. Reducing the resolution by a factor
of 2 should provide a four times reduction in the amount
of data spooled, and reducing the resolution by a factor
of 4 should provide a sixteen times reduction in the amount
of data spooled. For reliability, the scale factor should always
be less than 8. A scale factor of (1,1) (the default value) outputs
images at the full resolution of the device. Note that printing
systems with intellegent pre-processors may not actually reduce
the amount of output generated, as the pre-processor may compress
image data at the full resolution of the printer, however, some
systems may greatly benefit from resolution reduction, and the
gains measured may actually be double the expected amount.
On high resolution printers, a scaling factor of (2,2) often
provides output appears identical to using the full resolution
of the device. This is especially true of photographic images.
The default value is (1,1).
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetOutputScaleFactor(2, 2); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
void __stdcall PrnDIBSetDoWinScale(BOOL value);
Location: PrnDib.h and PrnDib.cpp
The TExcellentImagePrinter default behaviour is output images pre-scaled to the
full resolution of the printer. This can produce large print jobs.
This function (when set to true) causes "image chunks"
to be sent to the printer for re-scaling. If the image you are
printing is to be enlarged, this can amount to a significant
savings in print job size. If the image you are printing is
to be reduced, this can amount to a significant enlargement
in print job size. This function responds to scaling factors
introduced by the
PrnDIBSetOutputScaleFactor()
function.
The default value is FALSE.
Example:
{ BITMAPINFO * BitmapInfo; void * Bits; int BitmapWidth; int BitmapHeight; if (!LoadDIBFromFile("test.bmp", (PVOID*)&BitmapInfo, &Bits, &BitmapWidth, &BitmapHeight)){ ShowMessage("Bitmap load error"); return; } Printer()->BeginDoc(); PrnDIBSetDoWinScale(TRUE); PrintDIBitmap(Printer()->Canvas->Handle, BitmapInfo, Bits, FALSE, FALSE); Printer()->EndDoc(); FreeMemEx(BitmapInfo); FreeMemEx(Bits); ShowMessage("Printing Completed!"); }
Back to Functions and Structures
Windows "Bitmaps" come in two flavors. A Device Dependent Bitmap(DDB), and a Device Independent Bitmap (DIB). A DDB uses a format that is only known to the device that uses it, and should not be directly accessed by an application or another device. DDBstyle bitmaps are very fast, as they are in the native format of the device, however, it is an illegal operation to try to use a DDB bitmap from one device on another device (ie: from the screen to the printer), as the native format each device uses to store bitmaps may be different. If the format is the same on both devices then doing a BLT (pixel copy) operation will be successfull, however this practive is highly discouraged. Some device drivers (mainly printers) may be able to detect when you have sent a bitmap based on the screen to the printer, and attempt to print the bitmap anyway, however, this ability is highly specific to certain drivers and driver versions, therefore is not reliable. Note that using StretchDraw or other VCL raster functions to a printer canvas will often send a screen bitmap to the printer, leading to disaster on many printers. Note that this is not the only reason for bitmap printing failures. There are many cavets in bitmap printing to overcome. In the real world of deployed applications, its not as simple to print a bitmap as most examples tend to demonstrate.
As we have already mentioned, a DIB is a device independent bitmap, and can be used with any device. The DIB format is ideal for exchanging and saving bitmap data. A DIB may be encoded in many different formats, however, the formats are well documented, and any decent piece of software should be able to read any of the documented DIB formats (note that the VCL is only partially complient). The different DIB formats may vary in color depth, header encoding, and pixel encoding, however all the DIB formats are very well documented. A DIB consists of between two and five parts, of which, we are only interested in two. The Five parts are:
1) BitmapFileHeader.
2) BitmapInfoHeader (or possibly a BitmapCoreHeader).
3) Possibly a table of bit masks.
4) Possibly a color table.
5) The pixel data.
To use TExcellentImagePrinter, you will need a "pointer" (the address of a block of memory) that holds the BitmapInfoHeader (or BitmapCoreHeader), and a pointer that holds the pixel data for the bitmap you wish to print. Depending on your application, you may already have the pointers you wish to use. If not, we have included three functions in the PrnUtils unit to make it very easy for you to get these pointers from any one of the following sources:
1) A Bitmap File (a .bmp file for instance)
2) A bitmap stored in a stream (perhaps from a database or other resource)
3) A TBitmapObject (Image.Picture.Bitmap for example).
Please see the example code and the PrnUtils unit for usage.
Back to Functions and Structures