TPrintPreview Fixed header and footer

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

TPrintPreview Fixed header and footer

Postby henriqueltrindade » October 28th, 2011, 12:43 pm

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: October 28th, 2011, 12:28 pm

Re: TPrintPreview Fixed header and footer

Postby Kambiz » October 28th, 2011, 12:58 pm

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: 2429
Joined: March 7th, 2003, 7:10 pm

Re: TPrintPreview Fixed header and footer

Postby henriqueltrindade » October 31st, 2011, 10:28 am

Sorry, my lack of knowledge, but you have some simple example?
henriqueltrindade
Member
Member
 
Posts: 3
Joined: October 28th, 2011, 12:28 pm

Re: TPrintPreview Fixed header and footer

Postby henriqueltrindade » October 31st, 2011, 1:33 pm

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: October 28th, 2011, 12:28 pm

Re: TPrintPreview Fixed header and footer

Postby Kambiz » December 18th, 2011, 2:49 pm

TPrintPreview component has a method to calculate the bounding rectangle and the number of pages for the rich edit to be printed.
You can find more information about this method on the Readme file and sample demos.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: Google [Bot] and 3 guests

cron