Viewer object¶
- Table of contents
- Viewer object
A Viewer object is returned by the previewReport or previewToComponent methods.
This viewer object allows you to script the viewer panel, either in a Dialog or in a JPanel, using properties and methods, as listed here.
Properties¶
printPreview¶
A boolean. Get or set the paginated preview state of the panel. In paginated mode, CSS 3 @Page options will be used, and the media="print" CSS properties will be used. This mode will allow you to preview the PDF more precisely than the regular "html" preview.
statusVisible¶
A boolean. Get or set the visibility of the status panel at the bottom of the preview panel
toolbarVisible¶
A boolean. Get or set the visibility of the toolbar panel at the top of the preview panel (the buttons visible in that toolbar will depend on the options you set in the defaultPreviewParameters map)
Methods¶
incrementFontSize, decrementFontSize, resetFontSize¶
These methods produce the same effect as clicking on the font size buttons in the toolbar of the preview panel (they will have no effect in paginated view though)
zoomIn, zoomOut, resetZoom¶
These methods produce the same effect as clicking on the zoom buttons in the toolbar of the preview panel.
doSave¶
This method produces the same effect as clicking on the save button in the toolbar of the preview panel, depending a saveCallbackFunction being know, it will either call this one with a PDF byte[] result to be processed (saved on disk, on the database or on the server) by the Servoy method, or it will prompt for a location on the client's hard disk to save the PDF.
print¶
This method will print the current report in a background thread, thus allowing the user to keep working.
Even if this method doesn't block the Servoy client, the viewer itself will be disable during the process, to avoid any changes until the print has finished.
The signature is:
print([JSObject printParams])
- showDialog: a boolean, default to true
- size: one of the PRINTSIZE constants, default to NA_LETTER
- tray: cannot be used if size is set, one of the PRINTMEDIATRAY constants, default to MAIN
- orientation: one of the PRINTORIENTATION constants, default to PORTRAIT
- copies: an integer for the number of copies to print, default to 1
- sheetCollate: one of the PRINTSHEETCOLLATE constants, used when printing many copies (for example, the pages of a 3-page, 2-copy with PRINTSHEETCOLLATE.COLLATED will print as (1,2,3,1,2,3), but the pages of the same document with PRINTSHEETCOLLATE.UNCOLLATED will be printed as (1,1,2,2,3,3)) - default to COLLATED
- sides: one of the PRINTSIDE constants, useful for printers capable of printing on both sides of pages, default to ONE_SIDED
- preferredPrinter: a String with the name of a printer available, default to null which will use the default printer of the system
setSaveCallbackFuntion¶
Allow to set a function to be called back with the PDF byte[] by the save button of the toolbar or the doSave method of the Viewer object.
Returning true in this function will close the viewer (if it is displayed in its own window).
setPrintCallbackFuntion¶
Allow to set a function to be called back with the PDF byte[] by the save button of the toolbar or the print method of the Viewer object.
Returning true in this function will close the viewer (if it is displayed in its own window).
setBorder¶
Allow to set a border, uses the same syntax as the SolutionModel JSComponent.border
setHorizontalScrollbar¶
Allow to set the horizontal scroll bar policy, using one of the constant PREVIEW.HSCROLLBAR_ALWAYS, PREVIEW.HSCROLLBAR_ASNEEDED or PREVIEW.HSCROLLBAR_NEVER - default is PREVIEW.HSCROLLBAR_ALWAYS
setVerticalScrollBar¶
Allow to set vertical scroll bar policy, using one of the constant PREVIEW.VSCROLLBAR_ALWAYS, PREVIEW.VSCROLLBAR_ASNEEDED or PREVIEW.VSCROLLBAR_NEVER - default is PREVIEW.VSCROLLBAR_ALWAYS
update¶
This method will update the report in the preview panel, using a new template (file or content, depending on the "fromString" property of the contextObject) and a JSObject (new Object() or {}) contextObject containing any Servoy object to fill the report.
The signature is:
update(String templateNameOrContent, JSObject contextObject)
close¶
This method will close the viewer if it is displaying in its own window (but will do nothing if the viewer is viewed in a JPanel component).