TPrintPreview Fixed header and footer

Posted:
October 28th, 2011, 12:43 pm
by henriqueltrindade
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.
Re: TPrintPreview Fixed header and footer

Posted:
October 28th, 2011, 12:58 pm
by Kambiz
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.
Re: TPrintPreview Fixed header and footer

Posted:
October 31st, 2011, 10:28 am
by henriqueltrindade
Sorry, my lack of knowledge, but you have some simple example?
Re: TPrintPreview Fixed header and footer

Posted:
October 31st, 2011, 1:33 pm
by henriqueltrindade
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?
Re: TPrintPreview Fixed header and footer

Posted:
December 18th, 2011, 2:49 pm
by Kambiz
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.