| View previous topic :: View next topic |
| Author |
Message |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 6576
|
Posted: Fri Oct 21, 2005 8:48 pm Post subject: [How to] Print header and footer |
|
|
It's possible to make any kind of header and footer, but they must be implemented differently depending on your needs.
The component supports complex headers and footers - they can be multiline, contain images, tables, etc.
They must be assigned to TRVPrint component by the methods SetHeader and SetFooter.
See the example Demos\Delphi\Assorted\Printing\Headers\
There is a limitation of this method - the same header and footer for all pages, with no dynamic fields (like page number).
If you need different headers for different pages, you need to draw them yourself, using OnPagePrepaint event.
This demo shows how to draw a simple text as a header:
Demos\Delphi\Assorted\Printing\Printing\
Since you draw this text yourself, you can draw as many lines as you want.
RichViewActions (http://www.trichview.com/resources/actions/) process this event themselves and draw one plain text line. But they are limited with one line.
If you need to draw more complex headers (different for different pages), you can use TRVReportHelper component for this:
http://www.trichview.com/support/files/printheader.zip
This demo uses TRVReportHelper to draw header in TRVPrint.OnPagePrepaint event.
This demo draws the same header for all pages, but can be easily changed to draw different ones.
This demo shows how it can be done:
http://www.trichview.com/support/files/cppheader.zip , but it's for C++Builder.
And the last demo - using TRVReportHelper for drawing both header/footer and the main document:
http://www.trichview.com/support/files/a4.zip
It draws the result on the metafile, but can be easily changed to draw on the printer canvas. |
|
| Back to top |
|
 |
mamouri
Joined: 19 Aug 2006 Posts: 64
|
Posted: Sat Aug 19, 2006 12:52 pm Post subject: Printing both header and footer |
|
|
| I want print both header and footer in printheader demo. can you explain how it could done? |
|
| Back to top |
|
 |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 6576
|
Posted: Sat Aug 19, 2006 1:38 pm Post subject: |
|
|
Create another TRVReportHelper with the footer text.
Footer should be drawn in the same event, TForm1.RVPrint1PagePrepaint.
| Code: | procedure TForm1.RVPrint1PagePrepaint(Sender: TRVPrint; PageNo: Integer;
Canvas: TCanvas; Preview: Boolean; PageRect, PrintAreaRect: TRect);
begin
rvhHeader.Init(Canvas, PrintAreaRect.Right-PrintAreaRect.Left);
rvhHeader.FormatNextPage(PrintAreaRect.Bottom-PrintAreaRect.Top);
rvhHeader.DrawPageAt(PrintAreaRect.Left, PrintAreaRect.Top-rvhHeader.GetLastPageHeight,
1, Canvas, False, rvhHeader.GetLastPageHeight);
rvhFooter.Init(Canvas, PrintAreaRect.Right-PrintAreaRect.Left);
rvhFooter.FormatNextPage(PrintAreaRect.Bottom-PrintAreaRect.Top);
rvhFooter.DrawPageAt(PrintAreaRect.Left, PrintAreaRect.Bottom,
1, Canvas, False, rvhFooter.GetLastPageHeight);
end; |
As you can see, this code is simplified compating with the demo, because it uses DrawPageAt instead of DrawPage.
This code assumes that heights of header and footer are less than height of the main document on the page (height of the main document is passed as a parameter to FormatNextPage) |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|