guzinski / jasperphp

一个纯PHP库,用于读取使用'JasperSoft Studio'创建的JRXML文件并生成PDF格式的报告

1.0.0 2019-12-20 14:48 UTC

This package is auto-updated.

Last update: 2024-09-21 01:14:08 UTC


README

用于生成由JasperSoft Studio应用程序创建的报告的项目
纯PHP库,不依赖于Java服务器或Jasper服务器

请考虑捐款支持我们 Donate

支持的标签/组件

* 支持递归和无限子报告

其他特性

  • 活动记录

  • 通用示例

    <?php
    use JasperPHP\Report;
    use JasperPHP\Report2XLS;
    use JasperPHP\ado\TTransaction;
    use JasperPHP\ado\TLoggerHTML;
    
    //use PHPexcel as PHPexcel;
    /**
    * classe TJasper
    *
    * @author   Rogerio Muniz de Castro <rogerio@quilhasoft.net>
    * @version  2015.03.11
    * @access   restrict
    * 
    * 2015.03.11 -- create
    **/
    class TJasper
    {
        private $report;
        private $type;
    
        /**
        * method __construct()
        * 
        * @param $jrxml = a source xmlr filename
        * @param $param = a array whith params
        */
        public function __construct($jrxml,array $param)
        {
            $xmlFile=  $jrxml;
            $this->type = (array_key_exists('type',$param))?$param['type']:'pdf';
            error_reporting(0);
            switch ($this->type)
            {
                case 'pdf': 
                    $this->report =new JasperPHP\Report($xmlFile,$param);
                    JasperPHP\Pdf::prepare($this->report);
                    break;
                case 'xls':
                    JasperPHP\Excel::prepare();
                    $this->report =new JasperPHP\Report2XLS($xmlFile,$param);
                    
                    break;
            }
        }
        
        /**
        * method outpage()
        * 
        * @param $type = a type of output. ALERT: xls is experimental
        */
    
        public function outpage($type='pdf'){
            $this->report->generate();
            $this->report->out();
            switch ($this->type)
            {
                case 'pdf':
                    $pdf  = JasperPHP\Pdf::get();
                    $pdf->Output('Relatorio.pdf',"I");
                    break;
                case 'xls':
                    header('Content-Type: application/vnd.ms-excel');
                    header('Content-Disposition: attachment;filename="01simple.xls"');
                    header('Cache-Control: max-age=0');
                    // If you're serving to IE 9, then the following may be needed
                    header('Cache-Control: max-age=1');
                    // If you're serving to IE over SSL, then the following may be needed
                    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
                    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
                    header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
                    header ('Pragma: public'); // HTTP/1.0
                    $objWriter = PHPExcel_IOFactory::createWriter($this->report->wb, 'Excel5');
                    $objWriter->save('php://output');
                break;
            }
            
        }
        /**
        * method setVariable()
         * insert variable into report after output
        * 
        * @param $name = name of variable
        * @param $value = value of variable
        */
        public function setVariable($name,$value){
            $this->report->arrayVariable[$name]['initialValue'] = $value ;
        }
    }
    require('autoloader.php') ;
    require('../../tecnickcom/tcpdf/tcpdf.php'); // point to tcpdf class previosly instaled , 
                                                // on composer instalation is not necessaty 
    
    TTransaction::open('dev');
    $jasper = new TJasper('template.jrxml',$_GET);
    $jasper->outpage();
    ?>

    要求

    • PHP 5.2+
    • "tecnickcom/tcpdf":"6.2.*"

    如何使用此示例

    将数据库连接参数定义到文件config\dev.ini中
    查看文件src\ado\TConection.php以定义数据库类型
    示例URL
    https:///vendor/quilhasoft/JasperPHP/TJasper.class.php?param1=foo¶m2=bar
    传递到URL的URL参数是xmlr文件中定义的参数。

    使用composer

    将"quilhasoft/jasperphp":"dev-master"添加到您的composer配置文件中,并更新/安装

    实时示例

    • 基本测试:这里
    • 烧录测试,201页,托管在默认的hostgator服务器上:这里
    • 巴西支付方式"boleto"在"carne"中:这里
    • 巴西支付方式"boleto"在A4中:这里
      ** 巴西boleto项目在QuilhaSoft/JasperPHP-OpenBoleto中可用。

    许可证

    • MIT许可证