Re: Printing formatted text
- From: DB-1 <db1@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Aug 2006 22:14:03 +0300
"alanglloyd@xxxxxxx" wrote:
....
1 Split sting into elements of differing fonts by using the bold or
italic indicators as delimiters.
2 Get length of each element allocating fonts as necessary and using
Canvas.TextWidth.
3 Sum text widths and calculate spacing to justify (if fully justified)
That sounds a bit tedious, while Windows printing is no new comer any
more:) For over a decade I have used those ready made report generators,
QuickReport, FastReport, Rave etc. to do all my fancy printouts.
If you do not want to use those then consider the RichEdit control. That
can be found with simple examples somewhere from \DELPHI\DEMOS
subdirectory. Even it will cut your workload by 90%, compared to
allocating, measuring, calculating and collectiong everything by hand.
Once you have got your text coloured, bolded etc. to RichEdit
control(the Demo should cover that), then the burden for you is almost
over. Your job is now simply to say, RichEdit.Print, to format it both
on the screen and on the paper.
Here's some simple, old code how to set the margins to RichEdit.
procedure TForm1.SetRichEditMarginsInMm(aRichEdit: TRichEdit; aLeft,
aTop, aRight, aBottom: Integer);
//Before printing, set the Left, Top Right and Bottom
/ margins for it.
var
LogX, LogY: Integer;
R: TRect;
begin
LogX := GetDeviceCaps(printer.handle, LOGPIXELSX);
LogY := GetDeviceCaps(printer.handle, LOGPIXELSY);
with R do
begin
left := Trunc(LogX * (aLeft / 25.4)); // left margin in mm
top := Trunc(LogY * (aTop / 25.4)); // top margin in mm
// right and bottom margin mm
right := Printer.PageWidth - Trunc(LogX * (aRight / 25.4));
bottom := Printer.PageHeight - Trunc(LogY * (aBottom / 25.4));
end;
aRichEdit.PageRect := R;
end;
procedure TForm1.btnPrintClick(Sender: TObject);
begin
if MessageDlg('Do you want to print the contents ', mtConfirmation,
[mbYes, mbNo], 0) <> mrYes
then
Exit;
SetRichEditMarginsInMm(RichEd, 10, 10, 10, 10); // 10 mm margins on
all sides
RichEd.Print('The Caption');
end;
Sorry, not tested this section at all. Just cutted it out of a bigger
original code chunk. So good luck.
DB-1
.
- References:
- Printing formatted text
- From: GD1
- Re: Printing formatted text
- From: Maarten Wiltink
- Re: Printing formatted text
- From: GD1
- Re: Printing formatted text
- From: Maarten Wiltink
- Re: Printing formatted text
- From: GD1
- Re: Printing formatted text
- From: alanglloyd@xxxxxxx
- Printing formatted text
- Prev by Date: Arabic / Hebrew Edit Box
- Previous by thread: Re: Printing formatted text
- Next by thread: DataGrid and DataSet
- Index(es):
Relevant Pages
|