Skip to content
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:

  1. No any string written by echo.
  2. You shall not leave white space before <?php, or ?>
  3. in fact, we not recommend implement '?>' cause sometimes white space cause pdf cannot render correctly.
  4. When you include several files, ensure others file comply clause 1-3.
Clone this wiki locally