Visit Gigasoft's Web Site
ProEssentials v8 Help

Chapter 4: VCL Printing within Delphi

 

You can print ProEssentials based images either via simple DLL function calls or via low level API calls.

 

NOTE: To call DLL calls within Delphi, you  need to add the "Pegrpapi" unit to your uses clause.

 

Simple Printing with Dialog Intervention:

BOOL PElaunchprintdialog(hObject, bFullPage, lpPoint)

 

HWND 

hObject

* Use PEGraph1.hObject property.

BOOL 

bFullPage

Controls page size. Use 0 or 1

POINT FAR* 

lpPoint

Pointer to TPoint struct holding size.

 

This function invokes a modal print dialog. If bFullPage equals TRUE then lpPoint is ignored. If bFullPage equals FALSE then lpPoint must point to a TPoint that holds the size (in 1/100th millimeter units) of the image to export. Note that HWND, and BOOL are really 32 bit long integers within Delphi.

 

 

PrintStyleControl

This property controls the visibility of radio buttons and the option selected for printing on the print dialog. Type of ePrintStyleControl.   

Constant

Description

xNoPrintStyleControl

No control over Viewing Style

xPrintCurrentStyle

Current Viewing Style

xPrintDefaultMono

Switch to Mono Viewing Style

Replace the x prefix with either g(graph), sg(scientific graph), td(3D scientific graph), ps(polar/smith), or pc(pie chart).

 

DefOrientation

This property controls the default orientation of the printer paper when printing a ProEssentials object. Type of eDefOrientation.

Constant

Description

xDriverDefault

Use the printer driver

xLandscape

Landscape orientation.

xPortrait

Portrait orientation.

Replace the x prefix with either g(graph), sg(scientific graph), td(3D scientific graph), ps(polar/smith), or pc(pie chart).

 

PrintDpi

Controls the target resolution in DotsPerInch when printing. If set to Zero, graphic commands are sent directly to the printer:

Value

Description

0

If zero, the chart's image is sent to the printer via the actual graphic primitives and final resolution is based upon the printer's driver settings. This produces the sharpest graphics and may be the best setting when printing with ViewingStyle set to MonoChrome, BitmapGradientMode = False

100
---
600

If non zero, the chart image is prepared as a bitmap (at the specified PrintDpi) and this bitmap is sent to the printer. The default and recommend setting is 300. 300 produces a good looking image while not requiring a huge amount of memory to be sent to the printer.

 

HidePrintDpi

This property controls the visibility of the above PrintDpi end-user setting shown within the ProEssentials built-in print dialog:

Value

Description

TRUE

The End-User can not adjust the PrintDpi setting.

FALSE

The End-User can adjust the PrintDpi setting.

 

 

 

Simple Printing without Dialog Intervention:

BOOL PEprintgraph(hObject, nWidth, nHeight, nOrient)

 

HWND 

hObject

* Use PEGraph1.hObject.

INT 

nWidth

Width in 1/100th millimeters.

INT 

nHeight

Height in 1/100th millimeters.

INT 

nOrient

0=Driver Default, 1=Landscape, 2=Portrait.

 

This function prints the objects image to the default printer.  

 

If nWidth and nHeight are both zero, the image will print full page.

 

 

 

Lower Level Printing:

The following example shows how to place multiple images on a page.  You can also add other graphics and text as needed providing full control over the printed page.

 

The recommended method uses PEprintgraphEx which is a new v6 feature to simplify printing:

PEprintgraphEx(nDC:Integer; nWidth:Integer; nHeight:Integer; nOriginX:Integer; nOriginY:Integer)

 

Parameter

Description

nDC

Handle to target device context.

nWidth

Width in 1/100th millimeters.

nHeight

Height in 1/100th millimeters.

nOriginX

Top-Left horizontal location in 1/100th millimeters.

nOriginY

Top-Left vertical location in 1/100th millimeters.

 

This function sends GDI or GDIPLUS commands to the target device context (hDC) to place the object's image within the printer's page at the size and position specified. The current state of PrintDpi and PrintTechnology properties will control which system calls are used to transfer the image.

 

 

Be sure to remember to add "Math", "Printers" and "Pegrpapi" to your uses clause.

 

{******************************************************************
 ** Method of printing using PEprintgraphEx.
 ******************************************************************}

procedure TForm1.FormClick(Sender: TObject);
var
nLogPx: Integer;
nLogPy: Integer;
ChartSizeX: Single;
ChartSizeY: Single;

begin

Printer.Title := 'Printing ProEssentials';
Printer.BeginDoc;
Printer.Canvas.TextOut(100,100, 'Hello World!');


{'** Get DPI info **'}
nLogPx := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
nLogPy := GetDeviceCaps(Printer.Handle, LOGPIXELSY);

{'** Get Size in Inches **'}
ChartSizeX := Printer.PageWidth / nLogPx;
ChartSizeY := Printer.PageHeight / nLogPy;

{'** Convert to Himetrics, 1/100th millimeters **'}
ChartSizeX := ChartSizeX * 2540.0 / 2.0;
ChartSizeY := ChartSizeY * 2540.0 / 2.0;
ChartSizeX := ChartSizeX - 1270; {reduce horz size by margin, 1270 is 1/2 inch}

 

{'** Output image #1 **'}
PEprintgraphEx(PESGraph1.hObject, Printer.Handle, Floor(ChartSizeX),    Floor(ChartSizeY), 1270, 1270);


{'** just place same image, but could be from another control**}
PEprintgraphEx(PESGraph1.hObject, Printer.Handle, Floor(ChartSizeX),    Floor(ChartSizeY), Floor(ChartSizeX) + 1270, Floor(ChartSizeY));


Printer.EndDoc;


{' ** reset image to current aspect ratio **'}
PEresetimage(PESGraph1.hObject, 0, 0);


end;

 

 

 

{******************************************************************
 ** Lowest level, plays metafile to device context.
 ** Above code internally calls similar code when PrintDpi = 0
 ******************************************************************}

procedure TForm1.FormClick(Sender: TObject);

var

hMeta: Integer;

oldMM: Integer;

lresult: Longbool;

wSize: Integer;

hSize: Integer;

pt: TPoint;

begin

 

Printer.BeginDoc;

Printer.Canvas.TextOut(100,100, 'Hello World!');

 

{'** set mapping mode MM_TEXT **'}

oldMM := SetMapMode(Printer.Handle, 1);

 

{'** Set viewport org and extents **'}

hSize := Printer.PageHeight div 2;

wSize := Printer.PageWidth div 2;

lresult := SetViewportOrgEx(Printer.Handle, 0, hSize, @pt);

lresult := SetViewportExtEx(Printer.Handle, wSize, hSize, @pt);

 

{'** reset image shape to match shape defined by SetViewportExt **'}

PEresetimageEx(PESGraph1.hObject, wSize, hSize, 0, hsize);

hMeta := PEgetmeta(PESGraph1.hObject);

PEplaymetafile(PESGraph1.hObject, Printer.Handle, hMeta);

 

{'** just place same image, but could be from another control**}

lresult := SetViewportOrgEx(Printer.Handle, wSize, hSize, @pt);

lresult := SetViewportExtEx(Printer.Handle, wSize, hSize, @pt);

PEplaymetafile(PESGraph1.hObject, Printer.Handle, hMeta);

 

Printer.EndDoc;

 

{' ** reset mapping mode **'}

SetMapMode(Printer.Handle, oldMM);

 

{' ** reset image to current aspect ratio **'}

PEresetimage(PESGraph1.hObject, 0, 0);

end;

 

An important tip regarding low level printing and working with text and graphic mapping modes.   It's best to first do a SaveDC Windows API call, output either your graphics or text, perform a RestoreDC call, output other graphics and or text, followed by a RestoreDC when completed with the DC.