The viewer allows you to export a displayed report to PDF, PowerPoint, HTML, Text, Word, ODT Excel, ODC, CSV, SVG formats. A dashboard can be converted to PDF, Excel, HTML formats. To make the export work, additional settings of the viewer are not required.

 

Begin Export event

If you need to make some actions before export a report, you can use the onBeginExportReport event. The event will be invoked after the dialog export window with settings displayed. In arguments of the event the type of report export, a report and all settings of selected export will be transferred.

 

viewer.php

 

<?php

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

$viewer->onBeginExportReport = 'onBeginExportReport';

$viewer->renderHtml();

?>

 

function onBeginExportReport(args) {

var format = args.format;

var fileName = args.fileName;

var settings = args.settings;

}

 

 

 

The format property contains the type of selected export in the menu. It can take one of the values of the Stimulsoft.Report.StiExportFormat enumeration. You can find a detailed description of available values in the Export Report from Code chapter.

 

The fileName property contains file's name to save after export finished. The settings property contains all available settings for the current export type. Export settings and the name of a saved file can be changed, new values will be used automatically to export a report. For example, you need to change quality and image resolution for PDF export.

 

viewer.php

 

<?php

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

$viewer->onBeginExportReport = 'onBeginExportReport';

$viewer->renderHtml();

?>

 

function onBeginExportReport(args) {

if (args.format == Stimulsoft.Report.StiExportFormat.Pdf) {

args.settings.imageQuality = 0.90;

args.settings.imageResolution = 200;

}

}

 

 

 

To get access to export settings on the PHP server-side you should add the invoke of the event handler on the client-side and define the onBeginExportReport event of the same name in the file of the event handler. You can find a detailed description of the event work in the PHP Events Handler chapter.

 

viewer.php

 

<?php

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

$viewer->onBeginExportReport = true;

$viewer->renderHtml();

?>

 

 

handler.php

 

$handler->onBeginExportReport = function ($args) {

$fileName = $args->fileName;

$format = $args->format;

$settings = $args->settings;

 

return \Stimulsoft\StiResult::success();

};

 

 

 

Export settings and the name of a saved file can be changed to export a report. For example, you need to add a prefix for the file name and change quality and image resolution for PDF export.

 

handler.php

 

$handler->onBeginExportReport = function ($args) {

$args->fileName = 'PHP–' . $args->fileName;

 

if ($args->format == \Stimulsoft\StiExportFormat::Pdf) {

$args->settings->imageQuality = 0.90;

$args->settings->imageResolution = 200;

}

 

return \Stimulsoft\StiResult::success();

};

 

 

 

You can find a detailed description of available argument values in the Viewer Events chapter.

 

 

End Export event

If you need to make some actions after export a report before its saving, you should use the onEndExportReport event. In arguments of the event the type of report export and name and byte data of an exported file.

 

viewer.php

 

<?php

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

$viewer->onEndExportReport = 'onEndExportReport';

$viewer->renderHtml();

?>

 

function onEndExportReport(args) {

var format = args.format;

var fileName = args.fileName;

var data = args.data;

}

 

 

 

If you need, the name of a saved file or byte data can be changed, new values will be automatically used when saving a file.

 

By default, when exporting a file is saved to the computer local disk. To transfer an exported file to the PHP server-side you should add the invoke of events on the client-side in the onEndExportReport event, and on the server-side you should define the onEndExportReport event of the same name in the file of event handler. You can find a detailed description of event work in the PHP Events Handler chapter.

 

viewer.php

 

viewer.onEndExportReport = function (args) {

 

// Calling the server-side handler

Stimulsoft.Helper.process(args);

}

 

 

handler.php

 

$handler->onEndExportReport = function ($args) {

$fileName = $args->fileName;

$format = $args->format;

$data = $args->data;

 

return \Stimulsoft\StiResult::success();

};

 

 

 

In this case, after exporting, the obtained byte data will be transferred to the PHP server-side. Saving on the local computer will be disabled. For example, you want to save all exported files on the server side to the reports folder, and display a message after successfully saving the file:

 

handler.php

 

$handler->onEndExportReport = function ($args) {

$reportName = $args->fileName . '.' . $args->fileExtension;

file_put_contents('reports/' . $reportName, base64_decode($args->data));

 

return \Stimulsoft\StiResult::success("The exported report is saved successfully as $reportName");

};

 

 

Information

 

Byte data is transferred to the server-side in the Base64 coding, so before saving you should convert them into original byte stream using, for example, the base64_decode() standard PHP function.

 

 

 

You can find a detailed description of available argument values in the Viewer Events chapter.

 

 

Export Settings

Sometimes you should disable not used report export formats and leave only used. It allows you to load interface and simplify using the viewer. To disable not used formats of exports you should set the false value for corresponding properties of the viewer, for example.

 

viewer.php

 

<?php

$options = new \Stimulsoft\Viewer\StiViewerOptions();

$options->exports->showExportToDocument = false;

$options->exports->showExportToWord2007 = false;

$options->exports->showExportToCsv = false;

?>

 

 

 

Also, if needed, you can completely remove the display of dialog export windows, export will always be carried out with settings by default. In this case, settings can be controlled in export event. To disable dialog windows you should set the false value for the showExportDialog property.

 

viewer.php

 

<?php

$options = new \Stimulsoft\Viewer\StiViewerOptions();

$options->exports->showExportDialog = false;

?>

 

 

 

A full list of available options is in the Viewer Settings chapter.

 

 

Export Report from Code

In addition, report export is available with the help of a code. The exportDocument() method of report object is intended for this. You can find a detailed description in the Export Report from Code chapter.