运行JasperReport库的Python应用-即没有JasperServer [英] Python app to run JasperReport libraries - i.e. no JasperServer

查看:55
本文介绍了运行JasperReport库的Python应用-即没有JasperServer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望从python应用程序中尝试运行Jasper报告(已在iReports中编写并导出到xml),而不必与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. Is this possible?

我做了一些谷歌搜索,只遇到了一个2年的SO问题(建议的答案实际上需要JasperServer): 从内部运行jasper报告(使用iReport创建)没有jasperserver的python?

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?

除了标题中的它已过时"外,还有一些看起来很有希望的东西: http://code.activestate.com/recipes /576969-python-jasperreport-integration-it-is-陈旧/

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.

推荐答案

我使用了 py4j .我不得不用Java编写一个小程序. 以这为例,这很简单.

I used py4j. I had to write a small program in java. Using this as an example, it was simple.

配置构建环境并放置所有依赖项以打印qr代码更加困难.

It was more difficult to configure the build environment and put all the dependencies for printing qr-codes.

Python示例:

    from py4j.java_gateway import JavaGateway
    gateway = JavaGateway()
    gateway.entry_point.pdf_from_json('e:/test.jasper', 'e:/test.json', 'e:/test.pdf')

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

这篇关于运行JasperReport库的Python应用-即没有JasperServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆