-
Notifications
You must be signed in to change notification settings - Fork 45
Sample PHP Code
Ks Tan edited this page Aug 18, 2022
·
6 revisions
Render pdf is very easy, below is the source code.
<?php
require __DIR__."/vendor/autoload.php";
use simitsdk\phpjasperxml\PHPJasperXML;
$filename = __DIR__.'/sample.jrxml';
$data=[ ['user_id'=>0, 'fullname' => 'name1','email'=>'email1@a.com','gender'=>'M' ],
['user_id'=>1, 'fullname' => 'name2','email'=>'email2@a.com','gender'=>'F' ],
['user_id'=>2, 'fullname' => 'name3','email'=>'email3@a.com','gender'=>'M' ], ];
$config = ['driver'=>'array','data'=>$data];
$report = new PHPJasperXML();
$report->load_xml_file($filename)
->setDataSource($config)
->export('Pdf');
You shall avoid:
- No any string written by echo.
- You shall not leave white space before
<?php
, or?>
- in fact, we not recommend implement '?>' cause sometimes white space cause pdf cannot render correctly.
- When you include several files, ensure others file comply clause 1-3.
** Refer all .php example to know different kind of implementation