Page 1 of 1

about printer

Posted: 03 Dec 2015, 06:45
by allen
Hello! Print how to select range

example autodesk dwg truview : what to plot "windows"

Thank you

Image

Re: about printer

Posted: 03 Dec 2015, 21:06
by support
Hello Allen,

We recommend to use a TsgDrawingNavigator component for plotting a rectangular area selected with the mouse. To accomplish this, follow the steps below:

1) Load a drawing file into the TsgDrawingNavigator:

Code: Select all

FDNavigator.LoadFromFile(OpenPictureDialog1.FileName);

2) Activate the ClipRectangle mode to be able to select an area of the drawing to be plotted:

Code: Select all

FDNavigator.ClipRectangle := True
3) Select an area to be plotted with the mouse. When the area is selected, you can obtain the portion of the drawing bounded by the clipping rectangle as TGraphic object using a TsgDrawingNavigator.ActualGraphic property.

4) Use the Printer function to get access to the global TPrinter object and draw the given TGraphic on a page, as in the example below.

Code: Select all

uses  
  Windows, Graphics, Dialogs, ..., Printers;


procedure PrintImage(AGraphic: TGraphic);

const PO: array[Boolean] of TPrinterOrientation = (poPortrait, poLandscape);
var
  W, H: Double;
  PW, PH: Integer;
  R: TRect;
begin
  with Printer do
  begin
    Orientation := PO[AGraphic.Width > AGraphic.Height];
    W := PageWidth / AGraphic.Width;
    H := PageHeight / AGraphic.Height;
    if W > H then W := H;
    PW := Round(W * AGraphic.Width);
    PH := Round(W * AGraphic.Height);
    R := Bounds((PageWidth - PW) div 2, (PageHeight - PH) div 2, PW, PH);
    Printer.BeginDoc;
    try
      Printer.Canvas.StretchDraw(R, AGraphic);
    except
      Printer.EndDoc;
      ShowMessage('Problem while printing, please try again.');
    end;
    Printer.EndDoc;
  end;
end;

...

PrintImage(FDNavigator.ActualGraphic);
Mikhail