I\'m looking to try and run Jasper reports (that have been written in iReports and exported to xml) from within a python application, without having to communicate with a Jasper
I used py4j. I had to write a small program in java. Using this as an example, it was simple.
It was more difficult to configure the build environment and put all the dependencies for printing qr-codes.
Python example:
from py4j.java_gateway import JavaGateway
gateway = JavaGateway()
gateway.entry_point.pdf_from_json('e:/test.jasper', 'e:/test.json', 'e:/test.pdf')
Java example:
package jasper4py;
import py4j.GatewayServer;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JsonDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
public class JasperEntryPoint {
public static void main(String[] args) {
GatewayServer gatewayServer = new GatewayServer(new JasperEntryPoint());
gatewayServer.start();
System.out.println("Gateway Server Started");
}
public void pdf_from_json(String report, String data, String result) throws JRException, IOException {
Map<String, Object> parameters = new HashMap<String, Object>();
JsonDataSource dataSource = new JsonDataSource(JRLoader.getLocationInputStream(data));
JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, result);
}
}
Actually Jasper Reports are not implemented in Python, so the only way to have it serving to your Python code is to have Jasper Server running and awaiting Python requests over REST or other remote way of communication.
Simply - no way to have Jasper without Jasper (server) in Python