pdd_2003_1 Posted July 3, 2007 Share Posted July 3, 2007 I would like to call JasperReports from PHP page. Does anyone have a sample script? Link to comment Share on other sites More sharing options...
eos Posted December 10, 2007 Share Posted December 10, 2007 here is a sample fom internet:(http://charly-clairmont.developpez.com/tutoriels/php-jasper-reports/)Code:<?php $reportsPath ="/home/ccharly/publichtml/utils/reports/"; $reportFileName = "CommandesClients1"; $jasperReportsLib = "/home/ccharly/publichtml/utils/jasperlib"; if(extension_loaded('java')) { // lecture du répertoire où sont rengés les librairies utiles à JasperReports $handle = @opendir($jasperReportsLib); // ajout de tous les fichier jar au chemin de classe (Class Path) while(($new_item = readdir($handle))!==false) { $java_library_path .= 'file:'.$jasperReportsLib.'/'.$new_item .';'; } try { // chargement des librairies au classpath java_require($java_library_path); // création de la connexion JDBC $Conn = new Java("org.altic.jasperReports.JdbcConnection"«»); // driver $Conn->setDriver("com.mysql.jdbc.Driver"«»); // url de connexion $Conn->setConnectString("jdbc:mysql://localhost/erpmart"«»); // utilisateur $Conn->setUser("root"«»); // mot de passe $Conn->setPassword(null); // Compilation du fichier JRXML en fichier Jasper $sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager"«»); $report = $sJcm->compileReport($reportsPath .$reportFileName.".jrxml"«»); // Remplir le modèle avec les données $sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager"«»); $print = $sJfm->fillReport( $report, new Java("java.util.HashMap"«»), $Conn->getConnection() ); // Export du fichier au format pdf $sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager"«»); $sJem->exportReportToPdfFile($print, $reportsPath .$reportFileName.".pdf"«»); if (file_exists($reportsPath .$reportFileName.".pdf"«»)){ header('Content-disposition: attachment; filename="'.$reportFileName.'.pdf"'); header('Content-Type: application/pdf'); header('Content-Transfer-Encoding: binary'); header('Content-Length: '. @filesize($reportsPath . $reportFileName.".pdf"«»)); header('Pragma: no-cache'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); set_time_limit(0); @readfile($reportsPath .$reportFileName.".pdf"«») or die("problem occurs."«»); } } catch (JavaException $ex) { $trace = new Java("java.io.ByteArrayOutputStream"«»); $ex->printStackTrace(new Java("java.io.PrintStream", $trace)); print "java stack trace: $tracen"; } } ?> Link to comment Share on other sites More sharing options...
foukaridis Posted October 21, 2009 Share Posted October 21, 2009 Hi guys, I'm having trouble getting my variables across to my .jrxml file. I'm using php with a java bridge and reports created in ireports. I keep getting the following error: Report design not valid : 1. Query parameter not found : emis Here's my PHP code as well as my jrxml.Code:PHP: $compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager"); $report = $compileManager->compileReport(realpath("promotion.jrxml")); // Get the database connection $objClass = new Java("java.lang.Class"); $objClass->forName('com.mysql.jdbc.Driver'); $objDbm = new Java("java.sql.DriverManager"); $objDbConnect = $objDbm->getConnection("jdbc:mysql://localhost/db", "", ""); $fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager"); $params = new Java("java.util.HashMap"); $params->put('emis', '105480827'); $jasperPrint = $fillManager->fillReport($report, $params, $objDbConnect); $exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager"); $outputPath = realpath(".")."/"."promotion.pdf"; $exportManager->exportReportToPdfFile($jasperPrint, $outputPath); header ('Location: promotion.pdf'); JRXML: <queryString language="SQL"> <![CDATA[sELECT * FROM TABLE WHERE COLUMN = $P!{emis}]]> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now