-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathExporting a Report from Code with Changing Export Settings.php
72 lines (60 loc) · 2.43 KB
/
Exporting a Report from Code with Changing Export Settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
require_once '../vendor/autoload.php';
use Stimulsoft\Export\Enums\StiExportFormat;
use Stimulsoft\Export\StiPdfExportSettings;
use Stimulsoft\Report\Enums\StiEngineType;
use Stimulsoft\Report\StiReport;
// Changing the working directory one level up, this is necessary because the examples are in a subdirectory
chdir('../');
// Creating a report object
$report = new StiReport();
// Setting the server-side rendering mode
$report->engine = StiEngineType::ServerNodeJS;
// Processing the request and, if successful, immediately printing the result
$report->process();
// Loading a report by URL
// This method loads a report file and stores it as a compressed string in an object
// The report will be loaded from this string into a JavaScript object when using Node.js
$report->loadFile('reports/SimpleList.mrt');
// Building a report
// The report is not built using PHP code
// This method will prepare JavaScript code and pass it to Node.js, which will build a report and return the finished document
$result = $report->render();
if ($result) {
// After successfully building a report, creating a settings object and changing the necessary ones
$settings = new StiPdfExportSettings();
$settings->creatorString = 'My Company Name';
$settings->keywordsString = 'SimpleList PHP Report Export';
$settings->embeddedFonts = false;
// Calling the document export method with settings. Export is also performed using Node.js engine
// This method will save the exported report as a file
$filePath = 'reports/SimpleList.pdf';
$result = $report->exportDocument(StiExportFormat::Pdf, $settings, false, $filePath);
// Creating a message about the export result
$message = $result ? "Exporting the report to PDF was successful, the result has been successfully saved to '$filePath' file." : $report->nodejs->error;
}
else {
// If there is a build error, you can display the error text
$message = $report->nodejs->error;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
<title>Exporting a Report from Code with Changing Export Settings</title>
<style>
html, body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h2>Exporting a Report from Code with Changing Export Settings</h2>
<hr>
<?php
// Displaying the result message
echo $message;
?>
</html>