Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printing question

39 views
Skip to first unread message

J Smith

unread,
Aug 8, 2005, 4:43:51 PM8/8/05
to
I would like to print a couple of T-charts on a single page, togethe with
some small tabular data. How would I do that? Is this the right forum to
ask?

Thank you,

JS


Peter Below (TeamB)

unread,
Aug 9, 2005, 6:27:01 AM8/9/05
to

You would use the Printer object to manually print your pages. The chart
objects PrintPartialCanvas can be used to get the chart to render itself to
a canvas, e.g. the Printer.Canvas, at a specific position and size. The
Printer.Canvas methods like TextOut can be used to place text on the page
where you want it. Example:

var
RPage, RChart: TRect;
ResX, ResY, Y: Integer;
begin
printer.BeginDoc;
try
printer.canvas.font.Name := 'Arial';
printer.canvas.font.Size := 10;
// get physical page dimensions
RPage := Rect( 0,0,
GetDeviceCaps(Printer.handle, PHYSICALWIDTH),
GetDeviceCaps(Printer.handle, PHYSICALHEIGHT));
// get printer resolution, in dots per inch
ResX := GetDeviceCaps(Printer.handle, LOGPIXELSX);
ResY := GetDeviceCaps(Printer.handle, LOGPIXELSY);
// Apply some margins
RPage.Left := ResX; // left margin 1 inch
RPage.Right := RPage.Right - 3*ResX div 2; // right margin 1.5 inch
RPage.Top := 2* ResY; // top margin 2 inch
RPage.Bottom := RPage.Bottom - 2*ResY ; // bottom margin 2 inch
// move to origin of printer coordinate system, which is the top left
// corner of the printable area, not of the physical page
OffsetRect(Rpage, - GetDeviceCaps(Printer.handle, PHYSICALOFFSETY),
-GetDeviceCaps(Printer.handle, PHYSICALOFFSETY));

// print a title for the page
printer.canvas.font.Size := 18;
printer.canvas.font.Style := [fsBold];
Y:= RPage.Top;
printer.canvas.TextOut(RPage.Left, Y, 'Sample printout');
Y:= Y + printer.canvas.TextHeight('Üy');

// print the chart, assuming ResX = ResY here for simplicities sake
// set up a rect that places the chart on the left half of the
// page, with some gutter space between left and right half.
// Hight of rect is calculated to preserve the aspect ratio of the
// chart.
RChart := Rect(RPage.Left, Y,
(RPage.Right-RPage.Left-60) div 2 + RPage.Left,
Y);
RChart.Bottom := RChart.Top +
Round( Chart1.Height / Chart1.Width * (RChart.Right-RChart.Left));
Chart1.PrintPartialCanvas(Printer.canvas, RChart);

// place a one line description below the chart
printer.canvas.font.Size := 10;
printer.canvas.font.Style := [];
Y:= RChart.Bottom + ResY div 10;
printer.canvas.TextOut(RChart.Left, Y, 'Chart 1 printout');

// place a second copy of the chart to the right of the first
OffsetRect(RChart, RChart.Right-RChart.Left+60, 0);
Chart1.PrintPartialCanvas(Printer.canvas, RChart);

// place a one line description below the chart
printer.canvas.TextOut(RChart.Left, Y, 'Chart 2 printout');
finally
Printer.EndDoc;
end;
end;


--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


J Smith

unread,
Aug 9, 2005, 8:43:38 AM8/9/05
to
THANK YOU!


0 new messages