Samples

 

You can find a full code of on the GitHub.

 

 

 

To use the product, you should download the ZIP archive of the product from the Downloads page of our site, unpack it, and copy the contents of the /PHP folder to your Web server. This folder is a Web project that contains all the necessary files and resources for the product and samples for working with the viewer and designer.

 

To install the product in an existing project, you should copy the /vendor folder from the /PHP folder to the root directory of the project or use the Composer dependency manager by executing the following console command:

 

console

 

composer require stimulsoft/reports-php

 

 

 

When working with the product, in most cases, it is enough to use only PHP code, which ensures the operation of all the main features. For a more detailed configuration of the product and the use of all features, you must use JavaScript code. Next, two options for using certain features will be described - using PHP and JavaScript functions. Depending on your needs, you may use either the first or the second option.

 

To use the HTML5 Viewer (StiViewer) component you should add specified scripts and styles to the <head> block on the PHP page. You can do this using the StiJavaScript PHP class. In the constructor, you need to specify the type of component to deploy:

 

viewer.php

 

<head>

<?php

$js = new \Stimulsoft\StiJavaScript(\Stimulsoft\StiComponentType::Viewer);

$js->renderHtml();

?>

</head>

 

 

 

Also, you may connect all the necessary scripts using the <script> block. All product scripts are located in the vendor/stimulsoft/reports-php/public/scripts/ directory:

 

viewer.php

 

<head>

<script src="vendor/stimulsoft/reports-php/scripts/stimulsoft.reports.js" type="text/javascript"></script>

<script src="vendor/stimulsoft/reports-php/scripts/stimulsoft.viewer.js" type="text/javascript"></script>

</head>

 

 

 

For dashboards, you need to connect the following package:

 

console

 

composer require stimulsoft/dashboards-php

 

 

 

To view dashboards in the viewer, in addition you should add an appropriate script file, which contains all what is needed for work with dashboards.

 

index.php

 

<head>

<script src="vendor/stimulsoft/reports-php/scripts/stimulsoft.reports.js" type="text/javascript"></script>

<script src="vendor/stimulsoft/dashboards-php/scripts/stimulsoft.dashboards.js" type="text/javascript"></script>

<script src="vendor/stimulsoft/reports-php/scripts/stimulsoft.viewer.js" type="text/javascript"></script>

</head>

 

 

Information

 

You can find possible variants of deployment optimizations in the Optimization of script loading chapter.

 

 

 

After that, you can use PHP classes and functions to work with the viewer, which must be placed inside the <script> block. To display the viewer on the page, you should create an object of the HTML5 Viewer component (StiViewer), a visual part of the component will be deployed where the following script will be invoked.

 

viewer.php

 

<script type="text/javascript">

<?php

$viewer = new \Stimulsoft\Viewer\StiViewer();

$viewer->renderHtml();

?>

</script>

 

 

 

The viewer constructor arguments

The constructor of the StiViewer object can take optional arguments as input that affect its operation. There are two arguments in total:

 

viewer.php

 

<script type="text/javascript">

<?php

$viewer = new \Stimulsoft\Viewer\StiViewer($options, $viewerId);

$viewer->renderHtml();

?>

</script>

 

 

Name

Description

options

This is a set of options found in the Stimulsoft.Viewer.StiViewerOptions class. The options are divided into categories and contain all what you need for setting behavior and appearance of the viewer. You can find a detailed description of categories and options in the Viewer settings chapter.

viewerId

String identificator of the HTML element of the viewer. The "StiViewer" value is used by default.

 

 

The viewer display variants

There are two options for displaying the viewer: immediately at the site of the script and inside the specified HTML element of the page. The second option can be useful if, for example, you need to create and execute view scripts in advance, display the viewer on a button by clicking, display the viewer on a dynamically built page, and in other cases.

 

To render the viewer, you need to call the renderhtml() special function on the created object:

 

viewer.php

 

<script type="text/javascript">

<?php

$viewer = new \Stimulsoft\Viewer\StiViewer();

$viewer->renderHtml();

?>

</script>

 

 

 

When invoking renderhtml() function, visual part of the viewer will be rendered in the HTML page, where this function is invoked. If needed, the viewer can be displayed inside of the defined HTML element. In this case, you should transfer ID of this element or link to this element as function argument.

 

viewer.php

 

<script type="text/javascript">

<?php

$viewer = new \Stimulsoft\Viewer\StiViewer();

$viewer->renderHtml('viewerContent');

?>

</script>

 

<body>

<div id="viewerContent"></div>

</body>