# Jaspe Reports Viewer

(beans.jasperReportsServoyViewer)

## Overview

The `JasperReportsServoyViewer` is a Servoy bean designed to embed and display JasperReports within Servoy applications. It provides scripting capabilities for customizing visual properties such as background, foreground, font, size, and borders. The bean integrates with the `JasperReportsProvider` to support dynamic report viewing and customization. ## Functionality Reports can be rendered and displayed using the `js_showReport` method, which accepts parameters such as data source, report file, and locale. The viewer supports various export formats, configurable through scripting. The bean also facilitates managing paths for report directories and extra resource directories, ensuring integration with the JasperReports plugin. The `JRViewer` wrapper enables fine-tuned control of the viewer’s display behavior and export functionality.

## Properties Summarized

| Type                                                                           | Name                                                  | Summary                                                                                                                                                                        |
| ------------------------------------------------------------------------------ | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [background](#background)                             | Sets or gets the background color of the Bean.                                                                                                                                 |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [beanVersion](#beanversion)                           | This is a readonly property which returns the bean version.                                                                                                                    |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [beanViewerExportFormats](#beanviewerexportformats)   | Gets or gets the file save/export formats of the Bean's viewer.                                                                                                                |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [border](#border)                                     | Sets or gets the border type, width and color.                                                                                                                                 |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [displayMode](#displaymode)                           |                                                                                                                                                                                |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [font](#font)                                         | Sets or gets the font type of the Bean's viewer.                                                                                                                               |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [foreground](#foreground)                             | Sets or gets the foreground color.                                                                                                                                             |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [name](#name)                                         | Gets or sets the name of the Bean.                                                                                                                                             |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [relativeExtraDirectories](#relativeextradirectories) | Get or set the relative path or comma separated paths to the extra resource directories of the Servoy JasperReports plugin.                                                    |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [relativeReportsDirectory](#relativereportsdirectory) | Property for retrieving and setting the path to the reports directory, set by the current client, relative to the server reports directory of the Servoy JasperReports plugin. |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [transparent](#transparent)                           |                                                                                                                                                                                |

## Methods Summarized

| Type                                                                         | Name                                                                                                                                             | Summary                                                             |
| ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------- |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [getHeight()](#getheight)                                                                                                                        | Gets the height of the Bean.                                        |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [getLocationX()](#getlocationx)                                                                                                                  | Gets the x-coordinate of the Bean's top-left corner location.       |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [getLocationY()](#getlocationy)                                                                                                                  | Gets the y-coordinate of the Bean's top-left corner location.       |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [getWidth()](#getwidth)                                                                                                                          | Gets the width of the Bean.                                         |
| void                                                                         | [setLocation(x, y)](#setlocation-x-y)                                                                                                            |                                                                     |
| void                                                                         | [setSize(width, height)](#setsize-width-height)                                                                                                  | Sets the size of the Bean.                                          |
| void                                                                         | [showReport(source, report, parameters)](#showreport-source-report-parameters)                                                                   | Shows the indicated report in a JasperReports Viewer (in the Bean). |
| void                                                                         | [showReport(source, report, parameters, localeString)](#showreport-source-report-parameters-localestring)                                        | Shows the indicated report in a JasperReports Viewer (in the Bean). |
| void                                                                         | [showReport(source, report, parameters, localeString, moveTableOfContent)](#showreport-source-report-parameters-localestring-movetableofcontent) | Shows the indicated report in a JasperReports Viewer (in the Bean). |

## Properties Detailed

### background

Sets or gets the background color of the Bean.

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the border color of the bean

**Sample**

```js
myElement.background='#00ff00';
```

### beanVersion

This is a readonly property which returns the bean version.\
The bean version indicates which version of the Servoy JasperReports plugin the bean should be used with.

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the version of the bean; this should be in sync with the version of the plugin used

**Sample**

```js
application.output(myElement.beanVersion);
```

### beanViewerExportFormats

Gets or gets the file save/export formats of the Bean's viewer.

**Type**\
[Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) the file save/export formats of the viewer

**Sample**

```js
//also see plugins.jasperReports.viewerExportFormats
myElement.beanViewerExportFormats=[OUTPUT_FORMAT.PDF, OUTPUT_FORMAT.XLS];
```

### border

Sets or gets the border type, width and color.

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) border type, width and color

**Sample**

```js
myElement.border='LineBorder,4,#000000';
```

### displayMode

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the display mode of the viewer

**Sample**

```js
myElement.displayMode = JR_SVY_VIEWER_DISPLAY_MODE.FIT_WIDTH;
myElement.showReport(myDataSource,"myReport.jrxml",null);
```

### font

Sets or gets the font type of the Bean's viewer.

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the font type used in the viewer

**Sample**

```js
myElement.font='Tahoma,0,14';
```

### foreground

Sets or gets the foreground color.

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the foreground color

**Sample**

```js
myElement.foreground='#000000';
```

### name

Gets or sets the name of the Bean.

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the name of the Bean

**Sample**

```js
var beanName = myElement.name;
```

### relativeExtraDirectories

Get or set the relative path or comma separated paths to the extra resource directories of the Servoy JasperReports plugin.\
The paths are set per client and are relative to the server corresponding directories setting.

Please refer to the same property of the Servoy JasperReports plugin for more details.

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the relative path or paths to the client set extra directory/directories

**Sample**

```js
myElement.extraDirectories='relative/path/to/client/extraDirectory1';
```

### relativeReportsDirectory

Property for retrieving and setting the path to the reports directory, set by the current client, relative to the server reports directory\
of the Servoy JasperReports plugin.

Please refer to the same property of the Servoy JasperReports plugin for more details.

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the location of the client set reports directory, relative to the server set path

**Sample**

```js
myElement.relativeReportsDirectory = 'relativePath/to/serverReportsDirectory';
```

### transparent

**Type**\
[Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)

## Methods Detailed

### getHeight()

Gets the height of the Bean.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the height of the Bean

**Sample**

```js
var h = myElement.getHeight();
```

### getLocationX()

Gets the x-coordinate of the Bean's top-left corner location.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the x-coordinate of the Bean's top-left corner location

**Sample**

```js
var x = myElement.getLocationX();
```

### getLocationY()

Gets the y-coordinate of the Bean's top-left corner location.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the y-coordinate of the Bean's top-left corner location

**Sample**

```js
var y = myElement.getLocationY();
```

### getWidth()

Gets the width of the Bean.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the width of the Bean

**Sample**

```js
var w = myElement.getWidth();
```

### setLocation(x, y)

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **x** ;
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **y** ;

**Returns:** void

### setSize(width, height)

Sets the size of the Bean.

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **width** the width of the bean
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **height** the height of the bean

**Returns:** void

**Sample**

```js
myElement.setSize(800,600);
```

### showReport(source, report, parameters)

Shows the indicated report in a JasperReports Viewer (in the Bean).

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **source** the datasource (the server name, foundset or dataset) to run the report on
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **report** the report file to export and preview (relative to the reports directory)
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **parameters** the map of parameters to be used when previewing the report

**Returns:** void

**Sample**

```js
var params = new Object();
params.SUBREPORT_DIR = "./Subreport_Tests/";
var report = myElement.showReport(customers_to_orders,"/Subreport_Tests/main_report_fs.jrxml",params);
```

### showReport(source, report, parameters, localeString)

Shows the indicated report in a JasperReports Viewer (in the Bean).

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **source** the datasource (the server name, foundset or dataset) to run the report on
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **report** the report file to export and preview (relative to the reports directory)
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **parameters** the map of parameters to be used when previewing the report
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **localeString** the string which specifies the locale

**Returns:** void

**Sample**

```js
var params = new Object();
params.SUBREPORT_DIR = "./Subreport_Tests/";
var report = myElement.showReport(customers_to_orders,"/Subreport_Tests/main_report_fs.jrxml",params);
```

### showReport(source, report, parameters, localeString, moveTableOfContent)

Shows the indicated report in a JasperReports Viewer (in the Bean).

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **source** the datasource (the server name, foundset or dataset) to run the report on
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **report** the report file to export and preview (relative to the reports directory)
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **parameters** the map of parameters to be used when previewing the report
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **localeString** the string which specifies the locale
* [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) **moveTableOfContent** true in order to move the table of contents, false otherwise

**Returns:** void

**Sample**

```js
var params = new Object();
params.SUBREPORT_DIR = "./Subreport_Tests/";
var report = myElement.showReport(customers_to_orders,"/Subreport_Tests/main_report_fs.jrxml",params);
```

***
