I got this working quite well by tweaking some of the previous.
Andrew
procedure TForm1.FilePrintItemClick(Sender: TObject);
Var
i, lineCount, linesPerPage,Pn: integer;
scaleFactor, lh: single;
printerRect: TRect;
textarea: TRect;
mytextstyle: TTextStyle;
PageTitle : String;
begin
If Memo1.lines.count > 0 then
With PrintDialog1 Do // pick up the printer name etc
begin
PageTitle := Form1.caption; // for memo1
Printer.Canvas.Font.Assign(Memo1.Font);
scaleFactor:=Printer.XDPI / Screen.PixelsPerInch;
Printer.Canvas.Font.Size:=12; // was 12 or 10
Printer.Canvas.Font.Style:=[FSBold]; //bold
lh:= printer.Canvas.TextHeight(Memo1.text); //get the height from the memo characters
lh := Lh * (Printer.Canvas.Font.Size Div 2); // seems to work
linesPerPage:=trunc(Size(Printer.PaperSize.PaperRect.WorkRect).cy / lh) - 3; // was1 allow room for header
// Form1.caption := Inttostr( linesPerPage);
// exit;
printerRect:=Printer.PaperSize.PaperRect.PhysicalRect;
textarea:=Rect(50,50,Printer.PaperSize.Width - 50,Printer.PaperSize.Height-50);
mytextstyle := Printer.Canvas.TextStyle;
mytextstyle.Wordbreak:=True;
mytextstyle.SingleLine:=False;
Printer.BeginDoc;
Pn := 1;
lineCount:=1;
try
Printer.Canvas.TextOut(0,0 , ' Page: '+ IntToStr(Pn)+ ' ' + PageTitle) ;
for i:=0 to Memo1.Lines.Count-1 do
begin
Inc(lineCount); // leaves a blank line under the title line
Printer.Canvas.TextOut(200, trunc(lh*lineCount), Memo1.Lines);
if (lineCount > linesPerPage) then begin
lineCount:=1;
Printer.NewPage;
inc(pn);
Printer.Canvas.TextOut(0,0 , ' Page: '+ IntToStr(Pn)+ ' ' + PageTitle) ;
end;
end;
Printer.EndDoc;
except
//cancelled
end;
end;