Print and Print Preview
Two components print the content of an editor and show it on the screen before the printing.
| Component | Unit | Description |
|---|---|---|
TSynEditPrint | SynEdit.Print | Prints the text of an editor, with header, footer, margins, line numbers and the colors of the highlighter. |
TSynEditPrintPreview | SynEdit.PrintPreview | A control that shows the pages prepared by a TSynEditPrint. |
TSynEditPrint
pascal
SynEditPrint1.SynEdit := SynEdit1; // the editor to print
SynEditPrint1.Title := 'My document';
SynEditPrint1.Header.Add('$TITLE$', nil, taCenter, 1);
SynEditPrint1.Footer.Add('Page $PAGENUM$ of $PAGECOUNT$', nil, taRightJustify, 1);
SynEditPrint1.Print;Main properties
| Property | Description |
|---|---|
SynEdit | The editor to print (write only). The text, the font and the highlighter are taken from it. |
Lines, Font, Highlighter | The text and the look, if you want to print something that is not in an editor. |
Title, DocTitle | The title of the document, and the name of the job in the print queue. |
Header, Footer | Header and footer of every page. |
Margins | Margins of the page, with the indent of header and footer. |
Wrap | Wraps the long lines (default True). |
Highlight | Prints with the syntax highlighting (default True). |
Colors | Prints with the colors, also the background (default False). |
LineNumbers, LineNumbersInMargin, LineOffset | Prints the line numbers. |
SelectedOnly | Prints only the selection. |
Copies | Number of copies. |
TabWidth, Color | Tab size and background color. |
PageCount | Number of pages (after InitPrint). |
PrinterInfo | Information about the printer and the page. |
Header and footer
Each line of a header or footer is added with Add(Text, Font, Alignment, LineNumber). If Font is nil the DefaultFont is used. The text can contain these macros:
| Macro | Prints |
|---|---|
$PAGENUM$ | The number of the current page. |
$PAGECOUNT$ | The total number of pages. |
$TITLE$ | The title of the document. |
$DATE$, $TIME$ | The date, the time. |
$DATETIME$, $TIMEDATE$ | Date and time, time and date. |
Methods
Print prints all the pages, PrintRange(StartPage, EndPage) a range, PrintToCanvas draws a page on a canvas and InitPrint prepares the pages (needed to know PageCount before printing).
Events
OnPrintLine is fired for each line printed and OnPrintStatus reports the progress and lets you cancel the printing.
TSynEditPrintPreview
Put a TSynEditPrintPreview on a form, assign the SynEditPrint property and call UpdatePreview after the print component is ready.
| Member | Description |
|---|---|
SynEditPrint | The print component shown. |
ScaleMode, ScalePercent | Zoom: pscWholePage, pscPageWidth or a user defined percent. |
PageBGColor | Color of the page. |
PageNumber, PageCount | Current page and number of pages. |
FirstPage, PreviousPage, NextPage, LastPage | Navigation. |
Print | Prints from the preview. |
OnPreviewPage, OnScaleChange | Events fired when the page or the zoom change. |
Dialogs
| Unit | Dialog |
|---|---|
SynEdit.DPageSetup | Page setup dialog (TPageSetupDlg). |
SynEdit.FTestPrintPreview | A ready-made print preview form. |
SynEdit.PrintMarginsDialog | Dialog to edit the margins (TSynEditPrintMarginsDlg). |
Demo
See the Print and Preview demo.
