Skip to content

Print and Print Preview ​

Two components print the content of an editor and show it on the screen before the printing.

ComponentUnitDescription
TSynEditPrintSynEdit.PrintPrints the text of an editor, with header, footer, margins, line numbers and the colors of the highlighter.
TSynEditPrintPreviewSynEdit.PrintPreviewA 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 ​

PropertyDescription
SynEditThe editor to print (write only). The text, the font and the highlighter are taken from it.
Lines, Font, HighlighterThe text and the look, if you want to print something that is not in an editor.
Title, DocTitleThe title of the document, and the name of the job in the print queue.
Header, FooterHeader and footer of every page.
MarginsMargins of the page, with the indent of header and footer.
WrapWraps the long lines (default True).
HighlightPrints with the syntax highlighting (default True).
ColorsPrints with the colors, also the background (default False).
LineNumbers, LineNumbersInMargin, LineOffsetPrints the line numbers.
SelectedOnlyPrints only the selection.
CopiesNumber of copies.
TabWidth, ColorTab size and background color.
PageCountNumber of pages (after InitPrint).
PrinterInfoInformation about the printer and the page.

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:

MacroPrints
$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.

MemberDescription
SynEditPrintThe print component shown.
ScaleMode, ScalePercentZoom: pscWholePage, pscPageWidth or a user defined percent.
PageBGColorColor of the page.
PageNumber, PageCountCurrent page and number of pages.
FirstPage, PreviousPage, NextPage, LastPageNavigation.
PrintPrints from the preview.
OnPreviewPage, OnScaleChangeEvents fired when the page or the zoom change.

Dialogs ​

UnitDialog
SynEdit.DPageSetupPage setup dialog (TPageSetupDlg).
SynEdit.FTestPrintPreviewA ready-made print preview form.
SynEdit.PrintMarginsDialogDialog to edit the margins (TSynEditPrintMarginsDlg).

Demo ​

See the Print and Preview demo.

Released under the MPL 1.1 / GPL 2 dual license.