-
Notifications
You must be signed in to change notification settings - Fork 46
Sample PHP Code
Ks Tan edited this page Nov 7, 2018
·
6 revisions
Render pdf is very easy, below is the source code.
<?php
include_once 'phpjasperxml/PHPJasperXML.inc.php';
$PHPJasperXML = new PHPJasperXML("en","TCPDF");
//$PHPJasperXML->debugsql=true;
$PHPJasperXML->arrayParameter = array('para1'=>'1','para2'=>'2');
$PHPJasperXML->load_xml_file('file1.jrxml');
//if xml content is string, then $PHPJasperXML->load_xml_string($templatestr);
//$PHPJasperXML->sql = $sql; //if you wish to overwrite the sql
$dbdriver="mysql";//natively is 'mysql', 'psql', or 'sqlsrv'. the rest will use PDO driver.
$PHPJasperXML->transferDBtoArray(DBSERVER,DBUSER,DBPASS,DBNAME,$dbdriver);
$PHPJasperXML->outpage('I');
//$PHPJasperXML->outpage('D');
//$PHPJasperXML->outpage('f','/tmp/sample.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.