|
Texts printing
There are two text-oriented print jobs: TStringsPrintJob and TRichEditPrintJob. TStringsPrintJob prints the plain text from the Strings property, so, for instance, to print the TMemo contents, just copy the text from the memo into the Strings property and call the Print method.
procedure TForm1.PrintButtonClick(Sender: TObject);
begin
with StringsPrintJob1 do
begin
Strings:=Memo1.Lines;
Print;
end;
end;
TStringsPrintJob draws only page area itself, so you can draw any additional information in the header and footer area using the OnDraw event.
procedure TForm1.StringsPrintJob1Draw(Sender: TObject;
TheCanvas: TCanvas; PageIndex: Integer; TheRect: TRect;
Area: TDrawArea; Target: TDrawTarget);
begin
with TheCanvas do
case Area of
daHeader: DrawText(Handle,'The header',-1,TheRect,0);
daFooter: DrawText(Handle,PChar('Page '+IntToStr(PageIndex)),
-1,TheRect,DT_RIGHT or DT_SINGLELINE or DT_BOTTOM);
end;
end;
Do not forget to enable the header and footer in the Options property and set the needed size of the header and footer areas.
The rich text (RTF) can be printed by the TRichEditPrintJob component. Just drop the component onto your form and link it with TRichEdit component using the RichEdit property. The header and footer areas can be customized too.
|