This is how i’ve added a pdf javascript to the exported jasper report using PHP and postgreSQL for auto printing at the client side.

Make sure that you have successfully ran and tested your JavaBridge

<?php
$objStream = new Java(“java.io.ByteArrayOutputStream”);
$objJep = new Java(“net.sf.jasperreports.engine.JRExporterParameter”);
$objClass = new Java(“java.lang.Class”);
$objClass->forName(“org.postgresql.Driver”);
$objDbm = new Java(“java.sql.DriverManager”);
$objDbConnect = $objDbm->getConnection(“jdbc:postgresql://localhost/mypostgresdb”,”username”, “password”);
$objJcm = new Java(“net.sf.jasperreports.engine.JasperCompileManager”);
$objReport = $objJcm->compileReport(“report1.jrxml”);
$map =  new Java(“java.util.HashMap”);
$map->put(“parameter”,”value”);
$objJfm = new Java(“net.sf.jasperreports.engine.JasperFillManager”);
$objPrint = $objJfm->fillReport($objReport, $map, $objDbConnect);
$objJhe = new Java(“net.sf.jasperreports.engine.export.JRPdfExporter”);
$objJhe->setParameter($objJep->JASPER_PRINT, $objPrint );
$objParam = new Java(“net.sf.jasperreports.engine.export.JRPdfExporterParameter”);
//this is the script to automatically print the exported jasper PDF report
$scrpt = “this.print({bUI: false, bSilent: true, bShrinkToFit: false});this.closeDoc;”;
$objJhe->setParameter($objJep->OUTPUT_STREAM,$objStream);
$objJhe->setParameter($objParam->PDF_JAVASCRIPT,$scrpt);
$objJhe->exportReport();
header(“Content-type: application/pdf”);
echo java_cast($objStream->toByteArray(),”S”);
?>