Please see the Viewer demo.
// Printing functions
//Fit to paper
procedure TForm1.MIPrintClick(Sender: TObject);
var
W, H: Double;
PW, PH: Integer;
R: TRect;
begin
if StartPrint('Direct draw CAD to printer') then
try
W := Printer.PageWidth / Graphic.Width;
H := Printer.PageHeight / Graphic.Height;
if W > H then W := H;
PW := Round(W * Graphic.Width);
PH := Round(W * Graphic.Height);
R := Bounds((Printer.PageWidth - PW) div 2, (Printer.PageHeight - PH) div 2, PW, PH);
DrawTo(Printer, R, Graphic);
finally
EndPrint;
end;
end;
//Print at 1:1 scale
procedure TForm1.BtnPrint1Click(Sender: TObject);
const
cnstScaleFactor = 0.5;
var
vPxlsX, vPxlsY: Double;
R: TRect;
begin
if StartPrint('CAD Image VCL printing 1:1') then
try
vPxlsX := 1;
vPxlsY := 1;
if Assigned(Img) then
begin
vPxlsX := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
vPxlsY := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
if Img.Millimetres then
begin
vPxlsX := vPxlsX / cnstMMPerInch;
vPxlsY := vPxlsY / cnstMMPerInch;
end;
end;
R := Rect(0, 0, Round(vPxlsX * Graphic.Width * cnstScaleFactor),
Round(vPxlsY * Graphic.Height * cnstScaleFactor));
DrawTo(Printer, R, Graphic);
finally
EndPrint;
end;
end;
//Print the visible area
procedure TForm1.Printer1Click(Sender: TObject);
var
W, H: Double;
PW, PH: Integer;
vGr: TGraphic;
R: TRect;
begin
if StartPrint('Draw actual CAD to the printer via metafile') then
try
vGr := TMetafile.Create;
try
ActualGraphic(vGr);
W := Printer.PageWidth / vGr.Width;
H := Printer.PageHeight / vGr.Height;
if W > H then W := H;
PW := Round(W * vGr.Width);
PH := Round(W * vGr.Height);
R := Bounds((Printer.PageWidth - PW) div 2, (Printer.PageHeight - PH) div 2, PW, PH);
DrawTo(Printer, R, vGr);
finally
vGr.Free;
end;
finally
EndPrint;
end;
end;
Go to CAD VCL Enterprise