<< Click to Display Table of Contents >> Manual Creation of Complex Headers and Footers |
Your application knows very well, when it creates a new page, because it calls the method PageBreak (DLL: VpePageBreak). At this point you can easily insert complex headers and footers, even change the margins, etc.
The Event AfterAutoPageBreak() (DLL: VPE_AUTOPAGEBREAK)
To perform the manual insertion of complex headers and footers when VPE adds new pages by an AutoBreak (see “Automatic Text Break”), VPE fires the event AfterAutoPageBreak() (DLL: VPE_AUTOPAGEBREAK).
In reaction to this event you can insert headers and footers, change the page margins (see “Page Margins”), etc.
Be careful if you want to insert such headers / footers below the bottom margin! If you have the AutoBreak option activated, this might result into unwanted page breaks. Turn AutoBreakMode off in such case. VPE will crash due to a stack overflow, if you create an AutoBreak while processing this event, because VPE is re-entered and fires the event again and again before the processing of any of such event was finished.
NOTE: | There is one restriction for changing the page margins (see “Page Margins”) in response to the AutoBreak-Event: If the AutoBreak-Event was caused by an RTF Object using one of the following properties: • Keep paragraph intact • Keep paragraph with the next paragraph • Paragraph control the modification of the page margins might lead into wrong results of the output, because in such case VPE needs to know the dimensions of the margins of the next page before the event is fired. Normally this is not a problem, if you are sure your modifications of the margins will not affect the space needed by the broken RTF text (i.e. if the OutRect stays large enough to hold the broken text). |
Example:
For the VPE-Control: Private Sub PictureExport_AfterAutoPageBreak()
For the VPE-VCL: procedure OnAutoPageBreak(Sender: TObject);
// goto previous page
CurrentPage = CurrentPage – 1
// turn AutoBreak off, to avoid possible recursive stack overflow
AutoBreakMode = AUTO_BREAK_NO_LIMITS
// print a text below the last inserted object on this page
VpePrint(VLEFT, VBOTTOM, "to be continued...")
// turn AutoBreak on again
AutoBreakMode = AUTO_BREAK_ON
// go back to the current page
CurrentPage = CurrentPage + 1
// modify the top margin
nTopMargin = 5
// Print some header
VpePrint(1, 1, "some header...")
For the VPE-DLL:
case VPE_AUTOPAGEBREAK:
// goto previous page
VpeGotoPage(lParam, VpeGetCurrentPage(lParam) - 1);
// turn AutoBreak off, to avoid possible recursive stack overflow
VpeSetAutoBreak(lParam, AUTO_BREAK_NO_LIMITS);
// print a text below the last inserted object on this page
VpePrint(lParam, VLEFT, VBOTTOM, "to be continued...");
// turn AutoBreak on again
VpeSetAutoBreak(lParam, AUTO_BREAK_ON);
// go back to the current page
VpeGotoPage(lParam, VpeGetCurrentPage(lParam) + 1);
// modify the top margin
VpeSet(lParam, VTOPMARGIN, 5);
// Print some header
VpePrint(hDoc, 1, 1, "some header...");
break;