Custom helper / handle Method possible?

Stimulsoft Reports.PHP discussion
Post Reply
Dennis
Posts: 7
Joined: Tue May 30, 2017 3:24 pm

Custom helper / handle Method possible?

Post by Dennis »

Hi,

is it possible to build my own helper/handle Method and can i call this with an custom button from the Viewer?
I have modified the onEndExportReport function for testing to store the report as an export PDF Files to Server-side and it works fine, but i have to use the general Menu Button ( "save"-> "Adobe PDF File" ) to start the process.
My wish is to call the process from a single Button from toolbar.

Here is my code:

viewer.php

Code: Select all

<?php
require_once 'stimulsoft/helper.php';
?>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Stimulsoft Reports.PHP - JS Report Viewer</title>

	<!-- Report Office2013 style -->
	<link href="css/stimulsoft.viewer.office2013.whiteteal.css" rel="stylesheet">

	<!-- Stimusloft Reports.JS -->
	<script src="scripts/stimulsoft.reports.js" type="text/javascript"></script>
	<script src="scripts/stimulsoft.viewer.js" type="text/javascript"></script>
	
	<?php StiHelper::initialize(); ?>
	<script type="text/javascript">
		var options = new Stimulsoft.Viewer.StiViewerOptions();
		options.appearance.fullScreenMode = false;
		options.toolbar.showSendEmailButton = true;
		
		var viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
		
		// Process SQL data source
		viewer.onBeginProcessData = function (event, callback) {
			<?php StiHelper::createHandler(); ?>
		}
		
		// Manage export settings on the server side
		viewer.onBeginExportReport = function (args) {
			<?php StiHelper::createHandler(); ?>
			args.fileName = "Rechnung_<?php echo $_GET['id']; ?>";
		}
		
		// Process exported report file on the server side
		viewer.onEndExportReport = function (event) {
			event.preventDefault = false; // Prevent client default event handler (save the exported report as a file)
			<?php StiHelper::createHandler(); ?>
		}
		
		// Send exported report to Email
		viewer.onEmailReport = function (event) {
			<?php StiHelper::createHandler(); ?>
		}
		
		// Load and show report
		var report = new Stimulsoft.Report.StiReport();
		report.loadFile("reports/Report.mrt");
		report.dictionary.variables.getByName("param1").valueObject = "<?php echo $_GET['id']; ?>";
		viewer.report = report;
		viewer.renderHtml("viewerContent");
	</script>
	</head>
<body>
	<div id="viewerContent"></div>
</body>
</html>
modified function in handler.php to store the report as PDF File on Server Side.

Code: Select all

$handler->onEndExportReport = function ($event) {
	$format = $event->format; // Export format
	$data = $event->data; // Base64 export data
	$fileName = $event->fileName; // Report file name
	$file= $fileName.".".strtolower($format);
	
	$path2PDF=$_SERVER["DOCUMENT_ROOT"]."/stimulsoft/Libs/PHP/JS/pdf/";
	
	if(strlen(trim($fileName))>0) {
		$fp=fopen($path2PDF.$file, 'w+');
		fwrite($fp,base64_decode($data));
		fclose($fp);
	}
	//return StiResult::success();
	return StiResult::success("Export OK! Message from server side. (".$path2PDF.$file.")");
	//return StiResult::error("Export ERROR. Message from server side.");
};
thanks a lot
Greetings
Dennis
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

Re: Custom helper / handle Method possible?

Post by Vladimir »

Hello Dennis,

You can use the following code for create and use the custom button:

Code: Select all

var customButton = viewer.jsObject.SmallButton("exportPdfButton", "Export PDF", "emptyImage");
customButton.image.src = "https://www.stimulsoft.com/favicon.png";
customButton.action = function () {
	viewer.jsObject.postExport("Pdf", viewer.jsObject.getDefaultExportSettings("Pdf"));
}

var toolbarTable = viewer.jsObject.controls.toolbar.firstChild.firstChild;
var buttonsTable = toolbarTable.rows[0].firstChild.firstChild;
var customButtonCell = buttonsTable.rows[0].insertCell(0);
customButtonCell.appendChild(customButton);
Please place this code after viewer creation.

Thank you.
Post Reply