简体   繁体   English

运行 JasperReport 库的 Python 应用程序 - 即没有 JasperServer

[英]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.

相关问题 python作为“批处理”脚本(即从python运行命令) - python as a “batch” script (i.e. run commands from python) 不使用任何现成库的Python中的神经网络。 - Neural Networks in Python without using any readymade libraries…i.e., from first principles..help! 在 Python 中:如何获取从 Bash 运行的前一个进程的退出状态(即“$?”)? - In Python: how can I get the exit status of the previous process run from Bash (i.e. “$?”)? 为什么线程中的python套接字无法始终正确关闭(即,如果我连续多次运行该程序) - Why does my python socket in a thread not always close properly (i.e. if i run the program many times in a row) 是在“全局”类中定义的变量,即在Python中无效 - Is a variable defined in a class “global” i.e. invalid in Python 如何在 python 中的句子前添加数字,即递增 - How to add numbers i.e. increment before a sentence in python Notepad++ 的 Python 正确性(即 lint)分析 - Python correctness (i.e., lint) analyzing for Notepad++ 重新链接python对象(即通过引用传递) - Relink python object (i.e. pass by reference) 使用python即opencv检测裁剪人脸的运动模糊 - Detect motion blur of a cropped face with python i.e. opencv Python:将整数转换为计数(即3-&gt; 1,2,3) - Python : Convert Integers into a Count (i.e. 3 --> 1,2,3)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM