// print and format globals
var cpMin, PixH, PixW: longint;
ViewScale: double;
dc: THandle;
fr: TFormatRange;
ox, oy, w, h: LongInt;
MorePages: boolean;
PageMap, PrintMap: widestring;
PrtCnt, PgCnt, PgSum: integer;
PgWide, PgHigh, PgLft, PgRht, PgTop, PgBtm: double;
procedure TCmdForm.PrintPageMemo(Sender: TObject);
var
prm: TPrintParams;
begin
if PageControl1.PageCount>0 then
begin
if PrinterSetupDialog1.Execute then // choose printer,*paper,*orientation
begin
if PageSetupDialog1.Execute then // choose *paper,*orientation,margins
begin
if not Assigned(Printer) then // "catch all" for exit
begin
ShowMessage('No printer assigned.');
Exit;
end;
InitPrintParams(prm);
prm.SelStart:= PageMemo.SelStart;
prm.SelLength:= PageMemo.SelLength;
prm.JobTitle:= 'PageMemo Printing';
PageSetupToMargins(PageSetupDialog1, prm); // next below
PageMemo.Print(prm);
end else ShowMessage('Cancel selected.');
end else ShowMessage('Cancel selected.');
end else showmessage('No active document.');
end;
procedure TCmdForm.PageSetupToMargins(pg: TPageSetupDialog; var p: TPrintParams);
var
md : Single; // multiplier to convert to inches
begin
if pg.Units=unMM
then md:= 0.254
else md:= 0.001;
p.Margins.Left:= pg.Margins.Left*md*72; // PgLft*md*72;
p.Margins.Top:= pg.Margins.Top*md*72; // PgTop*md*72;
p.Margins.Right:= -pg.Margins.Right*md*72; // PgRht*md*72;
p.Margins.Bottom:= pg.Margins.Bottom*md*72; // PgBtm*md*72;
end;
procedure TCmdForm.PageMemoPrintAction(Sender: TObject; APrintAction: TPrintAction;
PrintCanvas: TCanvas; CurrentPage: Integer;
var AbortPrint: Boolean);
begin
if APrintAction=paPageStart then
begin
PrintCanvas.Brush.Color:= clBlue;
PrintCanvas.Brush.Style:= bsSolid;
PrintCanvas.Ellipse(100,100,200,200);
end;
end;