Python app to run JasperReport libraries - i.e. no JasperServer

孤街浪徒 提交于 2020-01-11 11:48:15

问题


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 JasperServer instance. Is this possible?

I've done some googling and only come across a 2 year old SO question (where the suggested answer actually requires JasperServer): Run jasper report (created with iReport) from within python without jasperserver?

And something that looks kind of promising, except for the "It is obsolete" in the title: http://code.activestate.com/recipes/576969-python-jasperreport-integration-it-is-obsolete/

I'm hoping it's obsolete because this is now an officially supported thing (dream on, Dave), but I can't find anything about it, if it is.


回答1:


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




回答2:


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);
    }
}


来源:https://stackoverflow.com/questions/23910516/python-app-to-run-jasperreport-libraries-i-e-no-jasperserver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!