<< Click to display table of contents >> TRVPrint |
This component allows printing TRichView, TRichViewEdit, TDBRichView, or TDBRichViewEdit. It is Invisible at run-time.
Unit [VCL/FMX] PtblRV / fmxPtblRV.
Syntax
TRVPrint = class(TCustomRVPrint)
TObject
TPersistent
TComponent
Printing or drawing pages
1.Assign the source component for printing (AssignSource method).
2.(optionally) Assign headers and/or footers (SetHeader, SetFooter).
3.Format pages (FormatPages method).
4.Now you can:
▪get a number of pages (PagesCount property);
▪display a print preview (using TRVPrintPreview component; see also DrawPreview, MakePreview, MakeScaledPreview, DrawPage, DrawPageAt methods);
▪print the whole document (Print method) or range of pages (PrintPages method).
5.When finished, you can release some temporally allocated memory (Clear).
PDF saving
1.Check of PDF saving is available (CanSavePDF).
2.Assign the source component for printing (AssignSource method).
3.(optionally) Assign headers and/or footers (SetHeader, SetFooter).
4.Save PDF (SavePDF)
5.When finished, you can release some temporally allocated memory (Clear).
By default, the component prints on the default printer, using its default properties. The global Printer object provides access to the available printers. You can switch the printer by assigning Printer.PrinterIndex. You can change orientation of pages by assigning Printer.Orientation. After these changes, before printing or previewing, call FormatPages.
Alternatively, you can use "virtual printer" to draw pages on any canvas. Assign VirtualPrinter.Active = True to use parameters (page size and DPI) specified in VirtualPrinter, instead of parameters of the current printer.
You can display some information about the process of paginating and printing:
▪OnFormatting occurs during paginating (FormatPages method);
▪OnSendingToPrinter occurs during printing (Print and PrintPages methods).
You can draw additional content using the following events:
▪OnPagePrepaint and OnPagePostpaint allow drawing on each page below/over TRichView document;
▪OnPrintComponent requests an image of an inserted control for printing.
There are also informational events; they occurred when some special item is drawn. You can store coordinates of these items and implement special processing (for example, adding hyperlinks when printing to PDF using some third-party library).
Margins are specified in Margins property.
Margins in TRVPrint
This picture illustrates the meaning of margin properties. Paragraph indents are not shown for simplification.
Margins are measured in Units (shown in red).
TRichView.LeftMargin, TRichView.RightMargin, TRichView.TopMargin and TRichView.BottomMargin are measured in “standard” pixels (1 pixel = 1/Style.UnitsPixelsPerInch of an inch; shown in blue).
Left and right margins can be swapped for even pages, if MirrorMargins is set to True.
See also ClipMargins property.
The picture above is for VCL and LCL version of the components.
FireMonkey version uses MarginsStroke property instead of MarginsPen property.
TRVPrint supports 3 types of headers and footers:
▪normal header and footer
▪header and footer for the first page (used only if TitlePage=True)
▪header and footer for even pages (used only if FacingPages=True)
Headers are assigned using SetHeader, footers are assigned using SetFooter methods.
Any TRichView document can be assigned as a header or footer. Positions of headers and footers are defined by HeaderY and FooterY.
Header and Footer
If a header and/or a footer is too long, size of the main document is adjusted to avoid overlapping:
Long Header Example
If you want more flexible headers / footers, consider:
▪printing document in several parts, each of them with its own header/footer;
▪using OnPagePrepaint event;
▪using TRVReportHelper.
See also: GetHeaderRect, GetFooterRect.
Some printers may have problems with advanced content (especially when you print to create PDF or metafile files). In this case, you can use the properties:
RVPrint contains an instance of TPrintableRV (descendant of TRichView) inside. This variable (named rv) is public and you can change some properties of it:
▪Color,
Changing other its properties is not recommended.
Example:
MyRVPrint.rv.Color := clWhite;
Note: this richview does not contain the full information about the printed document, just a formatting information; so you must provide that the source RichView is not destroyed while you are printing.
You can define the range of items to print, using MinPrintedItemNo and MaxPrintedItemNo properties. If these properties define a sub-range of items, only this sub-range (and only pages containing it) is printed.
These properties allow implementing an incremental printing: when the next portion of the document is ready, it can be printed below the previously printed fragment. This feature can be used for printing accounting journals, logs, etc.
The component draws a page content in the following order:
1.page background
2.OnPagePrepaint event
3.Header's text boxes and sidenotes having PositionInText=rvpitBelowText
4.Header
5.Header's text boxes and sidenotes having PositionInText=rvpitAboveText
6.Footer's text boxes and sidenotes having PositionInText=rvpitBelowText
7.Footer
8.Footer's text boxes and sidenotes having PositionInText=rvpitAboveText
9.Main document's text boxes and sidenotes having PositionInText=rvpitBelowText
10.Main document, including footnotes and endnotes
11.Main document's text boxes and sidenotes having PositionInText=rvpitAboveText
12.OnPagePostPaint event
Text boxes and sidenotes are drawn in the order of their positions in the parent document.
The following properties are used only in FireMonkey:
▪BestDPI.
See https://www.trichview.com/forums/viewtopic.php?p=250.
See also:
▪UpdatePaletteInfo method;
▪TRichView.PageBreaksBeforeItems;
▪TRichView.AssignSoftPageBreaks;
▪TRVReportHelper components;
▪RichViewAlternativePicPrint typed constant;
▪RichViewPixelsPerInch typed constant.
Demo projects:
▪Demos\*\Assorted\Printing\