TPrintPreview Fixed header and footer

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

TPrintPreview Fixed header and footer

Postby henriqueltrindade » 28/10/11 12:43

Hi,

I have three richedit! Header, footer and body. I would define every page header and footer fixed and dynamic body of the report.

------------------------
| Header text |
------------------------
| Text |
| Text |
| Text |
-----------------------
| Páge 1 Footer |
-----------------------


thank you.
henriqueltrindade
Member
Member
 
Posts: 3
Joined: 28/10/11 12:28

Re: TPrintPreview Fixed header and footer

Postby Kambiz » 28/10/11 12:58

To have header and footer regions on each page, you have to use OnNewPage event to draw those regions and also calculate the remaining rectangle (body) for drawing the richtext content.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2170
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: TPrintPreview Fixed header and footer

Postby henriqueltrindade » 31/10/11 10:28

Sorry, my lack of knowledge, but you have some simple example?
henriqueltrindade
Member
Member
 
Posts: 3
Joined: 28/10/11 12:28

Re: TPrintPreview Fixed header and footer

Postby henriqueltrindade » 31/10/11 13:33

Height of the rectangle is always greater than the size of the text of richedit, see the code:

function GetPreciseTextLen(ARichEditCtrl : TCustomRichEdit): integer;
var
gtlex : TGetTextLengthEx;
begin
with gtlex do
begin
// flags := GTL_PRECISE;
flags := GTL_DEFAULT;
codepage := CP_UTF8;
end;
Result := ARichEditCtrl.Perform(EM_GETTEXTLENGTHEX,WPARAM(@gtlex), 0 );
end;

Evento NewPage:

procedure TMainForm.PrintPreviewNewPage(Sender: TObject);
var
R: TRect;
MaxLen: Integer;
begin
with PrintPreview do
begin
Canvas.Pen.Width := 0;
Canvas.Brush.Style := bsCLear;
// Draws a frame with 1cm margin
R := PageBoundsAfterMargin;
RichEdit1.Text := Trim( RichEdit1.Text );
RichEdit.PageRect := R;
MaxLen := GetPreciseTextLen( RichEdit1 );
MaxLen := ConvertY( MaxLen, mmPixel, Units );
SetRect(R, 1000, 1000, PaperWidth - 1000, MaxLen );
InflateRect( R, 300, 300 );
Canvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
PaintRichText( R, TCustomRichEdit( RichEdit1 ), 0, nil );
end;
end;

The space increases if you have more lines

How to calculate the rectangle exactly the size of the text richedit?
henriqueltrindade
Member
Member
 
Posts: 3
Joined: 28/10/11 12:28


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest