
|
You are here: Home Delphi Stuffs NicePreview
NicePreview Component
Version: 1.00
Release Date: April 11st, 2003
Introduction
NicePreview is a free Delphi component that aimed to be an easy-to-use print preview
control. This is a shortcut to add a sophisticated print preview and off course
printing feature to your application, bypassing a nitty-gritty screen-printer
dpi (dot per inch) issue. All you have to do is dropping the component and write
some routines to paint on it like an ordinary screen canvas (96 dpi by default).
Yes, it uses screen dpi, not printer's. So you don't have to worry about converting
them to different dpi of printer. All in pixel coordinate.
NicePreview will not be notified when printer configurations change. So you
have to call ReadPrinterConfig method after executing TPrinterSetupDialog
or TPrintDialog, and redraw all pages to reflect the changes. Seems complicated,
but trust me, it's not difficult. See demo project included.


License
This library is released under Mozilla Public License. You can use it in your
freeware, shareware or commercial softwares. You can send your modification
to me, and if I decide to include it in the main distribution, I will add your
name as a contributor. You can read full licensing information here.
Installation
There is no special process to install it on Delphi. Just open NicePreviewD7.dpk
on Delphi IDE and press Install button. I use Delphi 7. If you use another Delphi
version, you may have to make some minor changes.
The component will appear in priyatna.org tab.
Methods
There are some main methods of the component:
- procedure ReadPrinterConfig;
This method will read current configuration of printer: page height, page
width, dot per inch, etc. NicePreview will not be notified when printer configurations
change. So you have to call this method after executing TPrinterSetupDialog
or TPrintDialog.
- function BeginPage: TCanvas;
This is will allocate a canvas (TMetafileCanvas) for a new page. You can start
drawing on the canvas returned by this function.
- procedure EndPage;
This method must be called when you finish drawing on the canvas returned
by BeginPage. Each BeginPage must be closed by EndPage.
- procedure Clear;
Clears all pages.
- procedure SaveToMetafile(FileName: string; Page: Integer);
Save page specified by Page to metafile.
- procedure PrintPage(Page: Integer);
Prints page specified by Page.
- procedure PrintAll;
Self explanatory.
- procedure ViewActualSize;
Zooms to 'Actual Size'.
- procedure ViewFitToWidth;
Zooms to 'Fit to Width'.
- procedure ViewWholePage;
Zooms to 'Whole Page';
- procedure ViewTwoPage;
Zooms to 'Two Page'.
- procedure ViewFourPage;
Zooms to 'Four Page'.
Properties
There are some main properties of the component:
- property PageIndex: Integer; (read write)
Specifies current selected page. If there is no selected page, it will contain
-1.
- property PageCount: Integer; (read only)
Self explanatory.
- property PageWidth: Integer; (read only)
Specifies page width in pixels. This property will reflect the real printer's
page width only after calling ReadPrinterConfig method.
- property PageHeight: Integer; (read only)
Specifies page height in pixels. This property will reflect the real printer's
page height only after calling ReadPrinterConfig method.
- property MarginLeft: Integer; (read write)
Specifies left margin in pixels. This property will reflect nothing, unless
you respect its value when drawing or rendering pages.
- property MarginTop: Integer; (read write)
Specifies top margin in pixels. This property will reflect nothing, unless
you respect its value when drawing or rendering pages.
- property MarginRight: Integer; (read write)
Specifies right margin in pixels. This property will reflect nothing,
unless you respect its value when drawing or rendering pages.
- property MarginBottom: Integer; (read write)
Specifies bottom margin in pixels. This property will reflect nothing,
unless you respect its value when drawing or rendering pages.
- property Magnification: Single; (read write)
Specifies current magnification. The 1.00 value will zoom to actual size,
where 0.1 will zoom out to tenth size, and 10.0 will zoom in to ten times
size. The valid range is 0.1 - 10.0. Set this value to zoom in or out.
- property PreviewMode: TPreviewMode; (read write)
TPreviewMode = (pmNormal, pmZoomIn, pmZoomOut);
pmNormal
Changes cursor to default, will select page if user click on control.
pmZoomIn
Changes cursor to 'Zoom In' cursor (magnifying glass with plus), will
zoom in if user click on control.
pmZoomOut
Changes cursor to 'Zoom Out' cursor (magnifying glass with minus), will
zoom out if user click on control.
- property Title: string; (read write)
Specifies the text that will appear in printer manager while printing
in progress.
- property OnChange: TNotifyEvent; (read write)
Occurs when user select a page or when Magnification, PreviewMode or PageCount
change.
Download
Download full source code and demo here:
|