[英]Python app to run JasperReport libraries - i.e. no JasperServer
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.我希望尝试从 python 应用程序中运行 Jasper 报告(已在 iReports 中编写并导出到 xml),而无需与 JasperServer 实例进行通信。 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?我已经做了一些谷歌搜索,只遇到了一个 2 岁的 SO 问题(建议的答案实际上需要 JasperServer): 在没有 jasperserver 的情况下从 python 中运行 jasper 报告(用 iReport 创建)?
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/还有一些看起来很有希望的东西,除了标题中的“它已经过时”: 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.我希望它已经过时了,因为这现在是官方支持的东西(做梦吧,戴夫),但我找不到任何关于它的信息,如果是的话。
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.实际上,Jasper Reports 不是在 Python 中实现的,因此将它提供给 Python 代码的唯一方法是让 Jasper Server 运行并通过 REST 或其他远程通信方式等待 Python 请求。
Simply - no way to have Jasper without Jasper (server) in Python简单 - 在 Python 中没有 Jasper(服务器)就没有 Jasper
I used py4j .我使用py4j 。 I had to write a small program in java.
我不得不用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: Java示例:
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.