1 unit Main;
2 
3 {$mode objfpc}{$H+}
4 
5 interface
6 
7 uses
8   Classes, ExtCtrls, PrintersDlgs, StdCtrls, SysUtils, FileUtil, Forms,
9   Controls, Graphics, Dialogs, TAGraph, TASeries, TASources;
10 
11 type
12 
13   { TForm1 }
14 
15   TForm1 = class(TForm)
16     PrintScaledPen: TButton;
17     Chart1: TChart;
18     Chart1LineSeries1: TLineSeries;
19     Panel1: TPanel;
20     Print: TButton;
21     PrintCanvas: TButton;
22     PrintDialog1: TPrintDialog;
23     RandomChartSource1: TRandomChartSource;
24     procedure PrintClick(Sender: TObject);
25   end;
26 
27 var
28   Form1: TForm1;
29 
30 implementation
31 
32 uses
33   OSPrinters, TAPrint, Printers;
34 
35 {$R *.lfm}
36 
37 { TForm1 }
38 
39 procedure TForm1.PrintClick(Sender: TObject);
40 const
41   MARGIN = 10;
42 var
43   r: TRect;
44   d: Integer;
45 begin
46   if not PrintDialog1.Execute then exit;
47   Printer.BeginDoc;
48   try
49     r := Rect(0, 0, Printer.PageWidth, Printer.PageHeight div 2);
50     d := r.Right - r.Left;
51     r.Left += d div MARGIN;
52     r.Right -= d div MARGIN;
53     d := r.Bottom - r.Top;
54     r.Top += d div MARGIN;
55     r.Bottom -= d div MARGIN;
56     if Sender = PrintCanvas then
57       Chart1.PaintOnCanvas(Printer.Canvas, r)
58     else
59       Chart1.Draw(TPrinterDrawer.Create(Printer, (Sender = PrintScaledPen)), r);
60   finally
61     Printer.EndDoc;
62   end;
63 end;
64 
65 end.
66 
67