在 PHP 网站中使用 Jasper 报告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4304023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:36:06  来源:igfitidea点击:

using Jasper reports in a PHP website

phpjasper-reports

提问by skyeagle

I would like to use Java reports 'report engine' to generate reports (HTML/PDF etc) and display them on my website.

我想使用 Java 报告“报告引擎”来生成报告(HTML/PDF 等)并将它们显示在我的网站上。

However, my website is using a PHP web framework. Can anyone suggest how I may be be able to use Jasper Reports within a PHP web framework?

但是,我的网站使用的是 PHP Web 框架。谁能建议我如何在 PHP Web 框架中使用 Jasper Reports?

回答by grantbacon

If you checkout the PHP REST Client on Github, or add it to your PHP project via Composer you will be able to run a report through web services.

如果您在 Github 上签出 PHP REST Client,或者通过 Composer 将其添加到您的 PHP 项目中,您将能够通过 Web 服务运行报告。

Your code should look something like:

您的代码应该类似于:

<?php
    $c = new \Jaspersoft\Client\Client(
    "http://localhost:8080/jasperserver-pro",
    "jasperadmin",
    "jasperadmin",
    "organization_1"
  );

    $report = $c->reportService()->runReport('/reports/samples/AllAccounts', 'html');
    echo $report;       
?>

That would retrieve a report in HTML format and store it in $report. Of course you can change html to pdf or xls or whatever format you wish to export to.

这将检索 HTML 格式的报告并将其存储在$report. 当然,您可以将 html 更改为 pdf 或 xls 或您希望导出为的任何格式。

If you wish to display PDFs or offer them for download, you will have to supply the binary data to some package that can handle it, or provide proper headers allowing it to be downloaded by a web browser.

如果您希望显示 PDF 或提供下载,您必须将二进制数据提供给一些可以处理它的包,或者提供适当的标题以允许它被 Web 浏览器下载。

I happen to be the one developing this package, so feel free to shoot me a line with any questions.

我碰巧是开发这个包的人,所以如果有任何问题,请随时给我留言。

回答by tsuyu

  1. using PHP/Java Bridge(http://php-java-bridge.sourceforge.net/).
  2. deploy the Java Bridge on tomcat Server.
  3. copy the jar jasper lib and mysql connector j lib in tomcat lib
  4. restart tomcat server
  5. edit php.ini(allow_url_include = On)
  6. include path of the library in php file. try refer this code for more information.. http://github.com/tsuyu/jasper-report-php-integration
  1. 使用 PHP/Java 桥(http://php-java-bridge.sourceforge.net/)。
  2. 在 tomcat 服务器上部署 Java Bridge。
  3. 将 jar jasper lib 和 mysql connector j lib 复制到 tomcat lib 中
  4. 重启tomcat服务器
  5. 编辑 php.ini(allow_url_include = On)
  6. 在 php 文件中包含库的路径。尝试参考此代码以获取更多信息.. http://github.com/tsuyu/jasper-report-php-integration

回答by DampeS8N

You will either need to build/find a java interpreter in php. Or more realistically, ask Java from PHP using Exec()

您将需要在 php 中构建/找到一个 java 解释器。或者更现实地,使用 Exec() 从 PHP 中询问 Java

EDIT

编辑

Or share a database connection and create a table for inter-communications. Which has some nice scalability points in its favor.

或者共享一个数据库连接并创建一个表用于相互通信。它有一些不错的可扩展性点。