I have installed the new version 2025.1 and everything is much easier than before. I find the new classes and ways of rendering very useful, although they still use JS instead of PHP.
All the examples on the web have worked for me, both the viewer, the export to PDF in the client-side, and the direct print.
The only one I can't get to work is the server-side rendering. It always returns a nodejs error: "RequestError: Unexpected token '@', "@\x13�,$n�<��<���" is not valid JSON"
I attach a code example, and the result returned by the render function (which is the result of the nodejs object), and comments in any lines for add more information.
The following example runs ok in client-side with viewer, with report export and with report direct print, with the same report file and the sames SQL's datasources.
Code: Select all
Route::any('test', function () {
\Stimulsoft\StiLicense::setPrimaryKey(file_get_contents(resource_path('reports/license/license.key')));
$nodejs = new \Stimulsoft\StiNodeJs();
$nodejs->binDirectory = dirname(config('node.path')); //this path is c:\Program Files\node
/*$result = $nodejs->installNodeJS();
if ($result)
$result = $nodejs->updatePackages();*/ //I've ran this block before, and result is "succesful"
$report = new \Stimulsoft\Report\StiReport();
$report->engine = \Stimulsoft\Report\Enums\StiEngineType::ServerNodeJS;
$report->node = $nodejs; // is necessary???
$report->onPrepareVariables = function (\Stimulsoft\Events\StiVariablesEventArgs $args) {
//do something
};
$report->onBeginProcessData = function(\Stimulsoft\Events\StiDataEventArgs $args)
{
//do something
};
$report->onEndProcessData = function(\Stimulsoft\Events\StiDataEventArgs $args)
{
//do something
};
$report->process();
$report->load(file_get_contents(resource_path('reports/sales/order/infOrder010.mrt')));
$result = $report->render(); //this return false, with this message: "RequestError: Unexpected token '@', "@\x13�,$n�<��<���" is not valid JSON"
if ($result) {
// After successfully building a report, calling the document export method. Export is also performed using Node.js engine
// This method will return the byte data of the exported document, or save it to a file
$filename = Storage::disk('private')->path("/tmp/Order.pdf");
$result = $report->exportDocument(\Stimulsoft\Export\Enums\StiExportFormat::Pdf, null, false, $filename);
if ($result !== false) {
$bytes = strlen($result);
$message = "The exported document takes $bytes bytes in $filename.";
}
else {
// If there is a export error, you can display the error text
$message = $report->nodejs->error;
}
}
else {
// If there is a build error, you can display the error text
$message = $report->nodejs->error;
}
echo $message;
});