Copyright © Kambiz R. Khojasteh. All rights reserved.
Get future component updates from http://www.delphiarea.com.
The print preview components consist of three visual components for low level print and print preview:
All the print preview components are fully customizable, and offer extensive set of events.
Add the following component's unit into a new or existing package:
The following packages must be added to the requires clause of your package:
Consider that Preview.pas
and DELPHIAREA.INC
must be in the search path of Delphi.
TPrintPreview is a descendent of TScrollBox and has properties of both TScrollBox component and TPrinter class.
The key features of the TPrintPreview component are:
PrintPreview ComponentKEY PROPERTIES
- Annotation: Boolean
Indicates whether the annotation drawing is active.- Background: Boolean
Indicates whether the background drawing is active.- CacheSize: Integer
Determines the maximum number of pages that the control can keep in memory.- CanScrollHorz (Read-only)
Indicates whether the preview page can scroll horizontally.- CanScrollVert (Read-only)
Indicates whether the preview page can scroll vertically.- Canvas: TCanvas (Read-only)
Provides access to a drawing surface that represents the page. Each page has its own canvas and any access to this property must be inside BeginDoc/EndDoc, BeginEdit/EndEdit, BeginReplace/EndReplace, BeginInsert/EndInsert, and BeginAppend/EndAppend blocks.- CanvasPageNo: Integer (Read-only)
Indicates the page number that Canvas belongs to it. When control's canvas is not a page canvas, value of CanvasPageNo is zero.- CurrentPage: Integer
Determines the current showing page number.- DirectPrint: Boolean
Determines whether the control creates preview pages or directly prints the pages on the printer.- Grayscale: TGrayscaleOptions
TGrayscaleOptions = set of TGrayscaleOption
TGrayscaleOption = (gsPreview, gsPrint)
Indicates whether the preview and/or print pages should be converted to grayscale.
gsPreview Shows preview pages in grayscale. However, Background and Anonation items keep their original colors. gsPrint Print pages in grayscale. - GrayBrightness: -100..100
Determines brightness of pages in grayscale mode.- GrayContrast: -100..100
Determines contrast of pages in grayscale mode.- IsDummyFormName: Boolean (Read-only)
Indicates whether the FormName property reperesents the printer's form name, or a dummy name generated by the control.- IsPaperCustom: Boolean (Read-only)
Indicates whether a custom paper is in use.- IsPaperRotated: Boolean (Read-only)
Indicates whether the paper's orientation is landscape.- Font: TFont
Specifies the default font for each new page. It is reommended to use a scalable font (e.g. TrueType and OpenType).- FormName: String
Determines the name of selected form for the paper size.- Orientation: TPrinterOrientation
TPrinterOrientation = (poPortrait, poLanscape)
Determines the the paper orientation of pages that will be created. The paper orientation could not change inside the BeginDoc and EndDoc block.- PDFDocumentInfo: TPDFDocumentInfo
Specifies Producer, Author, Creator, Subjet, and Title of the output PDF file (See SaveAsPDF method and PDF Output for details).- Pages[PageNo: Integer]: TMetaFile (Read-only)
Contains the list of prepared pages.- PageBounds: TRect (Read-only)
Specifies the bounding rectangle of the page in logical coordinates.- PageSize: TPoint (Read-only)
Specifies the paper size in logical coordinates.- PageDevicePixels: TPoint (Read-only)
Specifies the paper size in device coordinates (pixels).- PageLogicalPixels: TPoint (Read-only)
Specifies the paper size in screen coordinates (pixels).- PaperType: TPaperType
Specifies the paper size by the paper's type. There are 68 predefined sizes however by setting this property to pCustom you can use PaperWidth and PaperHeight properties to set your own custom paper size.- PaperHeight: Integer
Determines the physical height of the paper in logical units. Changing this property will change PaperType to pCustom. The value of PaperHeight must be between 1 and 32767.- PaperWidth: Integer
Determines the physical width of the paper in logical units. Changing this property will change PaperType to pCustom. The value of PaperWidth must be between 1 and 32767.- PaperView: TPaperPreviewOptions
Contains display parameters of the visible preview page (see PaperPreview Component for details).- PaperViewControl: TPaperPreview
Provides access to the control that displays a page (see PaperPreview Component for details).- PrintableAreaColor: Color
Determines the color to mark printer's printable area.- Printer: TPrinter (Read-only)
Returns a global instance of TPrinter to manage interaction with the printer.- PrinterInstalled: Boolean (Read-only)
Indicates whether is there any installed printer (driver) on the system.- PrinterPageBounds: TRect (Read-only)
Specifies the bounding rectangle of the printer's printable area in logical coordinates.- PrintJobTitle: String
Specifies the title of the print job on the system's print queue.- ShowPrintableArea: Boolean
When is True, shows bounding rectangle of printer's printable area on the preview.- State: TPreviewState (Read-only)
TPreviewState = (psReady, psCreating, psPrinting, psEditing, psLoading, psSaving, psSavingPDF, psSavingTIF)
Determines the current state of the control.
psReady The control is idle. psCreating The BeginDoc method is called and the control is preparing the preview pages to display. psPrinting One of the print methods is called and the control is printing pages on the printer. psEditing The BeginEdit method is called and control is editing a page. psReplacing The BeginReplace method is called and control is replacing a page with a new one. psInserting Either BeginInsert or BeginAppend method is called and control is inserting/appending a new page. psLoading The control is loading pages form a stream or file. psSaving The control is saving pages to a stream or file. psSavingPDF The control is saving pages as a PDF file. psSavingTIF The control is saving pages as a multi-page TIFF image. - SystemDefaultUnits: TUnits (Read-only)
Specifies the default measurement unit of the system. This unit is either mmHiMetric or mmHiEnglish.- TotalPages: Integer (Read-only)
Determines the total number of available pages to preview/print.- Units: TUnits
TUnits = (mmPixel, mmLoMetric, mmHiMetric, mmLoEnglish, mmHiEnglish, mmTWIPS, mmPoints)
Determines how the control interprets the measurement values (e.g. paper size, margins, font height, pen width, coordinates, and so on).
mmPixel 1 unit = 1 pixel mmLoMetric 1 unit = 0.1 millimeter mmHiMetric 1 unit = 0.01 millimeter mmLoEnglish 1 unit = 0.01 inch mmHiEnglish 1 unit = 0.001 inch mmTWIPS 1 unit = 1 twip = 1/20 point = 1/1440 inch mmPoints 1 unit = 1 point = 1/72 inch - UsePrinterOptions: Boolean
Specifies where the control looks for page information. When UseUserPage is true, the control uses the printer's paper size and orientation to for the paper size, otherwise it uses the paper size and orientation set in the control.- Zoom: Integer
Specifies how much the control scales pages on the screen. Changing this property will change ZoomState to zsZoomOther.- ZoomState: TZoomState
TZoomState = (zsZoomOther, zsZoomToWidth, zsZoomToHeight, zsZoomToFit)
Determines how the control scales pages on the screen.
zsZoomOther Scaling factor determines by Zoom property. zsZoomToWidth Whole the page's width will be visible. zsZoomToHeight Whole the page's height will be visible. zsZoomToFit Whole the page will be visible. - UserDefaultUnits: TUnits (Read-only)
Specifies the prefered measurement unit of the user. This unit is either mmHiMetric or mmHiEnglish.- ZoomSavePos: Boolean
Indicates whether the control keeps the old scroll positions when the zoom is changing.- ZoomStep: Integer
Determines the amount of changes in zoom percentage when it increments or decrements by a keyboard shurtcut or mouse wheel movement.- ZoomMin: Integer
Determines the minimum allowed value for the Zoom property.- ZoomMax: Integer
Determines the maximum allowed value for the Zoom property.PrintPreview ComponentKEY METHODS
- procedure BeginDoc
Initiates a new job and creates the Canvas.- procedure EndDoc
Finalizes the current job.- procedure NewPage
Starts a new page.- function BeginEdit(PageNo: Integer): Boolean
Intializes Canvas to edit the page specified by the PageNo parameter.- procedure EndEdit(Cancel: Boolean)
Finalizes editing the page. When Cancel parameter is True, the modification is ignored.- function BeginReplace(PageNo: Integer): Boolean
Intializes Canvas to replace the page specified by the PageNo parameter with a new one.
Calling this method raises the OnNewPage event.- procedure EndReplace
Finalizes replacing the page. When Cancel parameter is True, the modification is ignored.- function BeginInsert(PageNo: Integer): Boolean
Intializes Canvas to insert a new page before the page specified by the PageNo parameter. To insert the new page as the last page, pass a value large than TotalPages property as PageNo parameter.
Calling this method raises the OnNewPage event.- procedure EndInsert
Finalizes inserting the new page. When Cancel parameter is True, the modification is ignored.- function BeginAppend: Boolean
Intializes Canvas to insert a new page at the end of pages.
Calling this method raises the OnNewPage event.- procedure EndAppend
Finalizes appending the new page. When Cancel parameter is True, the modification is ignored.- function Delete(PageNo: Integer): Boolean
Removes the specified page.- function Exchange(PageNo1, PageNo2: Integer): Boolean
Swaps content of the specified pages.- function Move(PageNo, NewPageNo: Integer): Boolean
Changes position of the specified page to the new location.- procedure Clear
Clears all pages and resets the control.- procedure Print
Sends all pages to the printer.- procedure PrintPages(FromPage, ToPage: Integer)
Sends the selected range of pages to the printer.- procedure PrintPagesEx(Pages: TIntegerList)
Sends the selected pages to the printer.- procedure LoadFromStream(Stream: TStream)
Loads pages from a stream.- procedure SaveToStream(Stream: TStream)
Saves pages into a stream.- procedure LoadFromFile(const FileName: String)
Loads pages from a previously saved file.- procedure SaveToFile(const Filename: String)
Saves pages into a file.- procedure SaveAsTIF(const Filename: String)
Saves pages as a multi-frame TIFF image.- function CanSaveAsTIF: Boolean
Returns True if GDI+ is enabled to save pages as a multi-frame TIFF image.- procedure SaveAsPDF(const Filename: String)
Saves pages as a PDF file.- function CanSaveAsPDF: Boolean
Returns True if PDF writer module is installed.- procedure UpdateAnnotation
Forces the control to redraw the current page's annotation and update the screen.- procedure UpdateBackground
Forces the control to redraw the current page's background and update the screen.- procedure UpdateZoom
Forces the control to recalculate zoom scale and update the screen.- procedure ConvertPoints(var Points; NumPoints: Integer; InUnits, OutUnits: TUnits)
Converts the Points' coordinates from the input unit specified by InUnits parameter to the unit specified by the OutUnits.- function ConvertXY(X, Y: Inetger; InUnits, OutUnits: TUnits): TPoint
Returns the point's coordinate converted from the input unit specified by InUnits parameter to the unit specified by the OutUnits.- function ConvertX(X: Integer; InUnits, OutUnits: TUnits): Integer
Returns the conversion of a value reperesenting a horizontal offset or size from the input unit specified by InUnits parameter to the unit specified by the OutUnits.- function ConvertY(Y: Integer; InUnits, OutUnits: TUnits): Integer
Returns the conversion of a value reperesenting a vertical offset or size from the input unit specified by InUnits parameter to the unit specified by the OutUnits.- function BoundsFrom(AUnits: TUnits; ALeft, ATop, AWidth, AHeight: Integer): TRect
Converts a rectangle specified by its position and size from the specified measurement unit to the preview's units.- function RectFrom(AUnits: TUnits; ALeft, ATop, ARight, ABottom: Integer): TRect
Converts a rectangle specified by its corner positions from the specified measurement unit to the preview's units.- function PointFrom(AUnits: TUnits; X, Y: Integer): TRect
Converts a point from the specified measurement unit to preview's unit.- function XFrom(AUnits: TUnits; X: Integer): TRect
Converts a value reperesenting a horizontal offset or size from the specified measurement unit to preview's unit.- function YFrom(AUnits: TUnits; Y: Integer): TRect
Converts a value reperesenting a vertical offset or size from the specified measurement unit to preview's unit.- function PaintGraphic(X, Y: Integer; Graphic: TGraphic): TPoint
Renders the graphic specified by the Graphic parameter on the canvas at the location given by the coordinates (X, Y). The coordinates are in the preview's unit. The function returns the size of the graphic in the preview's unit.- function PaintGraphicEx(const Rect: TRect; Graphic: TGraphic; Proporional, ShrinkOnly, Cnter: Boolean): TRect
Draws the graphic specified by the Graphic parameter in the rectangle specified by the Rect parameter. The coordinates are in the preview's unit. The function returns the bounding rectangle of the graphic in the preview's unit.- function PaintGraphicEx2(const Rect: TRect; Graphic: TGraphic; VertAlign: TVertAlign; HorzAlign: THorzAlign): TRect;
Draws the graphic specified by the Graphic parameter in the rectangle specified by the Rect parameter. The coordinates are in the preview's unit. The function returns the bounding rectangle of the graphic in the preview's unit.- function PaintWinControl(X, Y: Integer; WinControl: TWinControl): TPoint
Renders the windowed control specified by the WinControl parameter on the canvas at the location given by the coordinates (X, Y). The coordinates are in the preview's unit. The function returns the size of the rendered image in the preview's unit.- function PaintWinControlEx(const Rect: TRect; WinControl: TWinControl; Proporional, ShrinkOnly, Cnter: Boolean): TRect
Draws the windowed control specified by the WinControl parameter in the rectangle specified by the Rect parameter. The coordinates are in the preview's unit. The function returns the bounding rectangle of the graphic in the preview's unit.- function PaintWinControlEx2(const Rect: TRect; Graphic: TGraphic; VertAlign: TVertAlign; HorzAlign: THorzAlign): TRect;
Draws the windowed control specified by the WinControl parameter in the rectangle specified by the Rect parameter. The coordinates are in the preview's unit. The function returns the bounding rectangle of the graphic in the preview's unit.- funtion PaintRichText(const Rect: TRect; RichEdit: TCustomRichEdit; MaxPages: Integer; pOffset: PInteger): Integer
Renders the content of the RichEdit control specified by the RichEdit parameter in the rectangle specified by the Rect parameter. The coordinates are in the preview's unit. If the content does not fit to the specified rectangle, the functions draw the rest in a new page. The function returns the number of pages used to render the content. The maximum number of pages allowed to print can be controlled by the MaxPages parameter. When MaxPages is zero, the function prints all the pages. The pOffset parameter is a pointer to an integer containing the offset (zero based) of the text, which rendering begins from that point. When the function does not render all the pages, the variable pointed by pOffset updates to the offset of the next part of the text that should be rendered in the next call, otherwise it sets to -1. The pOffset parameter can be nil. The functions returns the number of pages that are rendered.- funtion GetRichTextRect(var Rect: TRect; RichEdit: TCustomRichEdit; pOffset: PInteger): Integer
Claulates the smallest bounding rectangle required for rendering one page of the content of the RichEdit control specified by the RichEdit parameter in the rectangle specified by the Rect parameter. The coordinates are in the preview's unit. The pOffset parameter is a pointer to an integer containing the offset (zero based) of the text, which rendering begins from that point. When the content of the rich edit does not fit into the specified rectangle, the variable pointed by pOffset updates to the offset of the next part of the text that, otherwise it sets to -1. The pOffset parameter can be nil. The functions returns the number of bottom of the bounding rectangle..- procedure GetPrinterOptions
Gets the paper size and orientation of the control from the currently selected printer's paper and orientation. When the UsePrinterOptions property is True, after calling the BeginDoc method, the control automatically gets the paper size and paper orientation from the current printer.- procedure SetPrinterOptions
Sets the paper and orientation of the currently selected printer to paper size and orientation of the control. When the UsePrinterOptions property is False, the control automatically calls this method before beginning to print.- procedure SetPageSetupParameters(PageSetupDialog: TPageSetupDialog) (Delphi 7 and later only)
Sets the paper size and orientation of the page setup dialog to the control's paper size and orientation.- function GetPageSetupParameters(PageSetupDialog: TPageSetupDialog): TRect (Delphi 7 and later only)
Gets the paper size and orientation from the page setup dialog. This function returns the bounding rectangle of the page after applying margins specified by the page setup dialog.- function ScreenToPreview(X, Y: Integer): TPoint
Translates a given point in pixels from the screen resolution to the preview's unit.- function PreviewToScreen(X, Y: Integer): TPoint
Translates a given point in preview's unit to pixels in screen resolution.- function ScreenToPaper(const Pt: TPoint): TPoint
Translates a given point from screen coordinates to the paper coordinates. The paper coordinates are in the currently selected measurement unit.- function PaperToScreen(const Pt: TPoint): TPoint
Translates a given point from the paper coordinates to screen coordinates. The paper coordinates are in the currently selected measurement unit.- function ClientToPaper(const Pt: TPoint): TPoint
Translates a given point from client area coordinates to the paper coordinates. The paper coordinates are in the currently selected measurement unit.- function PaperToClient(const Pt: TPoint): TPoint
Translates a given point from the paper coordinates to the client area coordinates. The paper coordinates are in the currently selected measurement unit.- function FetchFormNames(FormNames: TStrings): Boolean
Fills the specified list with the name of available (predefined and custom) forms in the system.- function GetFormSize(const AFormName: String; out FormWidth, FormHeight: Integer): Boolean
Gets width and height of the specified form in the selected measurement unit.- function AddNewForm(const AFormName: String; FormWidth, FormHeight): Boolean;
Adds a custom form to the system. The form's size should be expressed in the selected measurement unit. The user must have full rights to the printer driver to call this function.- function RemoveForm(const AFormName: String): Boolean
Removes a custom form. This function does not delete the standard forms that the operating system defines. The user must have full rights to the printer driver to call this function.- procedure DrawPage(PageNo: Integer; Canvas: TCanvas; const Rect: TRect; Gray: Boolean)
Draws a preview page specified by its page number on the specified canvas and bouding rectangle.PrintPreview ComponentKEY EVENTS
- OnAnnotation: TPreviewPageDrawEvent
TPreviewPageDrawEvent = procedure(Sender: TObject; PageNo: Integer; Canvas: TCanvas) of object
If Annotation proprty set to True, occurs after a page is displayed. The items drawn on the provided canvas will appear over the preview page, but do not appear on print.- OnBackground: TPreviewPageDrawEvent
TPreviewPageDrawEvent = procedure(Sender: TObject; PageNo: Integer; Canvas: TCanvas) of object
If Background proprty set to True, occurs just before a page being displayed. The items drawn on the provided canvas will appear under the preview page, but do not appear on print.- OnBeginDoc: TNotifyEvent
Occurs when BeginDoc method calls.- OnEndDoc: TNotifyEvent
Occurs when EndDoc method calls.- OnNewPage: TNotifyEvent
Occurs immediately after a new page is created.- OnEndPage: TNotifyEvent
Occurs when a page is finished.- OnChange: TNotifyEvent
Occurs when the current page or content of the control changes.- OnStateChange: TNotifyEvent
Occurs when value of State property changes.- OnZoomChange: TNotifyEvent
Occurs when the zoom ratio of the view is changed.- OnPaperChange: TNotifyEvent
Occurs when size of orientation of paper changed.- OnBeforePrint: TNotifyEvent
Occurs just before sending pages to the printer.- OnAfterPrint: TNotifyEvent
Occurs when printing process is finished.- OnProgress: TPreviewProgressEvent
TPreviewProgressEvent = procedure(Sender: TObject; Done, Total: Integer) of object
Occurs periodically during the print and save as PDF and TIFF operations. You can check the value of State property to determine which operation is generating this event.- OnPageProcessing: TPreviewPageProcessingEvent
TPreviewPageProcessingEvent = procedure(Sender: TObject; PageNo: Integer; var Choice: TPageProcessingChoice) of object
TPageProcessingChoice = (pcAccept, pcIgnore, pcCancellAll)
Occurs during the print and save as PDF and TIFF operations, just before processing a page. You can check the value of State property to determine which operation is generating this event.
The Choice parameter can be set to one of the following values:
pcAccept (default) The operation will process the page. pcIgnore The operation will ignore this page. pcCancellAll The whole operation will be cancelled. - OnPrintAnnotation: TPreviewPageDrawEvent
TPreviewPageDrawEvent = procedure(Sender: TObject; PageNo: Integer; Canvas: TCanvas) of object
If Annotation proprty set to True, occurs after a page is printed. The items drawn on the provided canvas will place over the printed page.- OnPrintBackground: TPreviewPageDrawEvent
TPreviewPageDrawEvent = procedure(Sender: TObject; PageNo: Integer; Canvas: TCanvas) of object
If Background proprty set to True, occurs just before a page being printed. The items drawn on the provided canvas will place under the printed page.PrintPreview ComponentKEYBOARD SHURTCUTS
- Home
Scrolls the current page to the left most position.- Ctrl+Home
Scrolls the current page to the top most position.- End
Scrolls the current page to the right most position.- Ctrl+End
Scrolls the current page to the bottom most position.- Left
Scrolls the current page to the right with the number of pixels specified in HorzScrollbar.Increment property.- Shift+Left
Scrolls the current page one pixel to the right.- Ctrl+Left
Scrolls the current page one screen to the right.- Right
Scrolls the current page to the left with the number of pixels specified in HorzScrollbar.Increment property.- Shift+Right
Scrolls the current page one pixel to the left.- Ctrl+Right
Scrolls the current page one screen to the left.- Up
Scrolls the current page down with the number of pixels specified in VertScrollbar.Increment property.- Shift+Up
Scrolls the current page one pixel down.- Ctrl+Up
Scrolls the current page one screen down.- Down
Scrolls the current page up with the number of pixels specified in VertScrollbar.Increment property.- Shift+Down
Scrolls the current page one pixel up.- Ctrl+Down
Scrolls the current page one screen up.- Page Up
Shows the previous page.- Ctrl+Page Up
Shows the first page.- Page Down
Shows the next page.- Ctrl+Page Down
Shows the last page.- Plus (Numeric Pad)
Zoom in by the amount specified in the ZoomStep property.- Minus (Numeric Pad)
Zoom out by the amount specified in the ZoomStep property.PrintPreview ComponentMOUSE WHEEL FUNCTIONS
- Wheel Down
Scrolls the current page up with the number of pixels specified in VertScrollbar.Increment property.- Wheel Up
Scrolls the current page down with the number of pixels specified in VertScrollbar.Increment property.- Ctrl+Wheel Down
Zoom out by the amount specified in the ZoomStep property.- Ctrl+Wheel Up
Zoom in by the amount specified in the ZoomStep property.- Shift+Wheel Down | Wheel Press + Wheel Down
Shows the next page.- Shift+Wheel Up | Wheel Press + Wheel Up
Shows the previous page.PrintPreview ComponentPDF OUTPUT
To save preview pages in PDF format, you should have either dsPDF library or Synopse PDF library
dsPDF Library
You can find dsPDF library at http://delphistep.cis.si, under freeware components section.
Please consider that dsPdf is postcardware, and demo version displays message "This is demo". If you want to get the library without the demo message, you must send the author (Grega Loboda) a postcard of the town or city you live via (snail) mail.
Note: The demo version of dsPdf library does not save document properties (Producer, Author, Creator, Subject, and Title of the document).
Synopse PDF Library
You can download Synopse PDF library from http://www.synopse.info, and it is freeware.
After obtaining Synopse PDF library, open the Preview.pas file and define the SYNOPSE compiler directive in the begining of the file.
Note: Synopse PDF library is still in development stage, and may fail to generate PDF for some sort of contents.
IMAGE TRANSPARENCY
As default, TPrintPreview does not allow image transparency because transparency on printers is not guaranteed. As a work around, you can combine images as needed, and then draw the final image to the printer.
However, if you need image transparency and you think that all target printers of your application will support SrcErase, srcAnd, and SrcInvert raster operations, you can set AllowTransparentDIB global variable to True, so that the control takes care of transparent images.
PrintPreview ComponentTHIRD PARTY RICH EDIT CONTROLS
There are some third party rich edit controls that are not derived from TCustomRichEdit class (e.g. TRxRichEdit control of RxLibrary). In other hand, PaintRichText and GetRichTextRect methods of the TPrintPreview component expect a TCustomRichEdit as their RichEdit parameter.
To workaround this problem and pass such kind of controls to PaintRichText or GetRichTextRect methods, safely type cast the control to TCustomRichEdit. The TPrintPreview component needs only Handle property of rich edit controls for sending Windows messages to them.
Actually, in this way you can print any control that supports EM_GETTEXTLENGTHEX and EM_FORMATRANGE messages.
PrintPreview ComponentKNOWN ISSUES
- If Units property is set to mmHiMetric and width or height of the paper size is bigger than 32767 units, the page will not display correctly. This happens because SetWindowExtEx API function expects a two bytes signed integer (Smallint) as its X and Y parameters, so values bigger than 32767 are interpreted as negative values.
- When the zoom is not on the actual size (100%), the control may display the preview of the scalable fonts inproperly. Always use TrueType or OpenType fonts in your print.
- The PaintRichText and GetRichTextRect methods use EM_FORMATRANGE message of the rich edit control. This message has different behavior on different versions of the rich edit control. In addition, this message ignores the embedded objects in the RTF text.
- The preview of a rich text may differ from its printed version. This issue is a known rich edit control problem. To print RTF text, it is recommended to set DirectPrint property to True and regenerate the pages.
- After editing a page (e.g. calling BeginEdit method) for several times, you see this action gets slower each time. Editing page involves merging two Windows metafiles, adding new content to the old page. Windows API has problem on merging metafiles, and I cannot do anything about it. If you need to edit a page more than 10 times, it's better to create a new page and replace it with the old one (e.g. calling BeginReplace method).
The TThumbnailPreview control is a special ListView for showing thumbnails of pages generated by TPrintPreview control.
Not only you can use this control to show thumbnail of pages, but also the users can get benefit of it to do some actions (e.g. delete, print, reorder, ...) on the selected pages.
ThumbnailPreview ComponentKEY PROPERTIES
- AllowReorder: Boolean
When set to true, user can reorder pages using drag and drop opration.- DisableTheme: Boolean
Specifies whether the control should bypass Windows theme or not.- DropTarget: Integer (Read-only)
Specifies the number of page that is target of drag operation.- Grayscale: TThumbnailGrayscale
TThumbnailGrayscale = (tgsPreview, tgsNever, tgsAlways)
Determines whether the thumbnails should be displayed in grayscale.
tgsPreview The value of Grayscale property of the attached TPrintPreview control determines whether the thumbnails are in grayscale ro not. tgsNever Regardless of the value of Grayscale property of the attached TPrintPreview control, the thumbnails never display in grayscale. tgsAlways Regardless of the value of Grayscale property of the attached TPrintPreview control, the thumbnails always display in grayscale. - IsGrayscaled (Read-only)
Indicates whether the thumbnails are currently grayscaled.- MarkerColor: TColor
Determines the border color around the thumbnail page which is the current page on the PrintPreview control.- PrintPreview: TPrintPreview
Determines the PrintPreview control that feeds pages to the control.- Selected: Integer
Specifies the number of page that is selected. In a multiselect scenario, this is the first selected page.- SpacingHorizontal: Integer
Specifies the horizontal space (in pixels) between two thumbnails.- SpacingVertical: Integer
Specifies the vertical space (in pixels) between two thumbnails.- Zoom: Integer
Specifies the relative size of each thumbnail to its actual page size in percent.ThumbnailPreview ComponentKEYKEY METHODS
- function PageAt(X, Y: Integer): Integer
Returns the page number of thumbnail at the specified location of the control's client area or zero if no thumbnail found.- procedure PageAtCursor
Returns the page number of thumbnail under the mouse cursor or zero if no thumbnail found.- procedure GetSelectedPages(Pages: TIntegerList)
Fills the list with page number of currently selected thumbnails.- procedure SetSelectedPages(Pages: TIntegerList)
Selects the thumbnails with the specified page numbers.- procedure DeleteSelectedRemoves the selected pages.
- procedure PrintSelectedPrint the selected pages.
ThumbnailPreview ComponentKEYKEY EVENTS
- OnPageBeforeDraw: TPageThumbnailDrawEvent
TPageThumbnailDrawEvent = procedure(Sender: TObject; PageNo: Integer; Canvas: TCanvas; const Rect: TRect; var DefaultDraw: Boolean) of object
Occurs before a thumbnail beging drawn.- OnPageAfterDraw: TPageThumbnailDrawEvent
TPageThumbnailDrawEvent = procedure(Sender: TObject; PageNo: Integer; Canvas: TCanvas; const Rect: TRect; var DefaultDraw: Boolean) of object
Occurs after a thumbnail is drawn.- OnPageClick: TPageNotifyEvent
TPageNotifyEvent = procedure(Sender: TObject; PageNo: Integer) of object
Occurs when the user clicks a thumbnail.- OnPageDblClick: TPageNotifyEvent
TPageNotifyEvent = procedure(Sender: TObject; PageNo: Integer) of object
Occurs when the user double clicks a thumbnail.- OnPageInfoTip: TPageInfoTipEvent
TPageInfoTipEvent = procedure(Sender: TObject; PageNo: Integer; var InfoTip: String) of object
Occurs when the mouse pointer moves over a thumbnail that can display an InfoTip text.- OnPageSelect: TPageNotifyEvent
TPageNotifyEvent = procedure(Sender: TObject; PageNo: Integer) of object
Occurs when a page selected.- OnPageUnselect: TPageNotifyEvent
TPageNotifyEvent = procedure(Sender: TObject; PageNo: Integer) of object
Occurs when a selected page deselects.
The TPaperPreview control represents a sheet of paper in the TPrintPreview control, but you can use it as standalone too.
Usage of the TPaperPreview control is very similar to TPainBox control of Delphi. However, in opposite of TPainBox, the TPaperPreview control only repaints the invalidated area and caches the last paint and do not generate redundant OnPaint events. Because of that, when you need to repaint its content, you have to explicitly call one of Invalidate or Repaint methods.
The TPaperPreview control also can be captioned. In this case the caption appears under the page.
PaperPreview ComponentKEYKEY PROPERTIES
- Alignment: TAlignment
Controls the horizontal placement of the caption.- BorderColor: TColor
Determines the color of border around the pager.- BorderWidth: TBorderWidth
Determines the size of border around the pager.- Caption: String
Specifies the text that appears under the paper.- PageRect: TRect (Read-only)
Gets the bounding box of the paper in control's coordinates.- PaperWidth: Integer
Indicates the value of width (in pixels) of the page.- PaperHeight: Integer
Indicates the value of height (in pixels) of the page.- PaperSize: TPoint
Gets and sets width and height (in pixels) of the paper all at once.- PreservePaperSize: Boolean
When set to True, changes in BorderSize, ShadowSize, Caption, and ShowCaption properties do not alter value of PaperWidth and PaperHeight properties and change control's size. When set to False, the control's size keeps constant but PaperWidth and PaperHeight properties adjust to the available space.- ShadowColor: TColor
Determines the color of paper's shadow.- ShadowWidth: TBorderWidth
Determines the size of shadow for the paper.- ShowCaption: Boolean
Indicates whether the control's caption is visible.PaperPreview ComponentKEY METHODS
- function ClientToPaper(const Pt: TPoint): TPoint
Translates a point on the client area of the control to its corresponding point on the paper area.- function PaperToClient(const Pt: TPoint): TPoint
Translates a point on the paper area to its corresponding point on the client area of the control.- procedure SetBoundsEx(ALeft, ATop, APaperWidth, APaperHeight: Integer)
Sets the Left, Top, PaperWidth, and PaperHeight properties all at once.PaperPreview ComponentKEY EVENTS
- OnPaint: TPaperPaintEvent
TPaperPaintEvent = procedure(Sender: TObject; Canvas: TCanvas; const Rect: TRect) of object
Occurs when the paper needs to be painted.
Because the control caches the last paint, you need to call one of Invalidate or Repaint methods to update the paper's content.
Special thanks to:
The Print Preview components (TPrintPreview, TThumbnailPreview, and TPaperPreview) are freeware. You may copy components' files AS LONG AS YOU COPY ALL OF THEM. If you want to change the source code in order to improve the components' features, performance, etc. please send me the new source code so that I can have a look at it. The changed source code should contain descriptions what you have changed, and of course your name. The only thing you MAY NOT CHANGE is the ORIGINAL COPYRIGHT INFORMATION.
The Print Preview components (TPrintPreview, TThumbnailPreview, and TPaperPreview) are provided "AS IS" without any warranty of any kind, either express or implied. The entire risk as to the quality and performance of the software is with you. The author is NOT liable for any DAMAGES resulting from the use and misuse of the components, especially he is NOT liable for DAMAGES that were caused BY ANY VERSION WHICH HAS NOT BEEN PROGRAMMED BY THE AUTHOR HIMSELF.
END OF DOCUMENT |