- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsHow can I print a header and footer at the top and bottom of each page from a TRichEdit?
I want to be able to print a title centered on the top of each page and "Page X " at the bottom of each page.
Thanks for your help.
Rich
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: mokulePosted on 2007-03-14 at 12:53:30ID: 18721653
This will do but without formatting. Only pure text.
: TObject); geHeight); inter.Page Width - printer.Canvas.TextWidth(H eader)) div 2,y,Header); 'A');
ageWidth); ,RichEdit1 .Lines[i]) ; 'A'); * Printer.PageHeight then inter.Page Width - printer.Canvas.TextWidth(F ooter)) div 2,y,Footer); geHeight); inter.Page Width - printer.Canvas.TextWidth(H eader)) div 2,y,Header); argin)* Printer.PageHeight); inter.Page Width - printer.Canvas.TextWidth(F ooter)) div 2,y,Footer);
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, printers, ComCtrls; //, DB, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
Button1: TButton;
PrintDialog1: TPrintDialog;
RichEdit1: TRichEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender
const
LeftMargin = 0.05;
TopMargin = 0.05;
BottomMargin = 0.05;
Header = 'Header';
var
i: integer;
x,y: integer;
Footer: string;
PageNum: integer;
begin
if PrintDialog1.Execute then
begin
Printer.BeginDoc;
y := Round(TopMargin*Printer.Pa
printer.Canvas.TextOut((Pr
y := y + printer.Canvas.TextHeight(
PageNum := 1;
for i := 0 to RichEdit1.Lines.Count-1 do
begin
x := Round(LeftMargin*Printer.P
printer.Canvas.TextOut(x,y
y := y + printer.Canvas.TextHeight(
if y > (1-TopMargin-BottomMargin)
begin
Footer := 'Page ' + IntToStr(PageNum);
Inc(PageNum);
printer.Canvas.TextOut((Pr
Printer.NewPage;
y := Round(TopMargin*Printer.Pa
printer.Canvas.TextOut((Pr
end;
end;
y := Round((1-TopMargin-BottomM
Footer := 'Page ' + IntToStr(PageNum);
printer.Canvas.TextOut((Pr
Printer.EndDoc;
end;
end;
end.