Coder Social home page Coder Social logo

quilhasoft / jasperphp Goto Github PK

View Code? Open in Web Editor NEW
59.0 14.0 22.0 11.97 MB

Pure PHP library to read JRXML files made in "JasperSoft Studio" and generate reports in PDF/XLS

Home Page: https://jasperphp.net

License: MIT License

PHP 100.00% HTML 0.01%
jrxml-file jrxml-pdf report-generator jaspersoft jaspersoft-studio jasperserver jasper-reports php-reports php-reporting-tools

jasperphp's Introduction

alt text

JasperPHP

Library to generate reports created with the JasperSoft Studio application
Pure PHP library, without a java server or Jasper Server

Please, consider donating funds to support us Donate

See more blog, documentation, and more on https://jasperphp.net

Export formats

PDF
XLS

Supported tags/components

TAG/component Status TAG/component Status
Basic elements
Text Field OK Static Text OK
Image OK Break OK
Rectangle OK Line OK
SubReport* OK Barcode OK
Composite elements
Page Number OK Total Pages OK
Current Date OK Page X of Y OK
Bands
Title OK Page Header OK
Group OK Detail OK
Column Header OK Column Footer OK
Page Footer OK Sumary OK
Background OK Style OK
Frame OK dynamic table OK
* Subreports are supported recursively and unlimited

Other features

  • sum, average,minimum, max of variables
  • read and calculate subreport variables
  • array of objects as input data
  • textfield with html render with data replacement
  • active record
  • Conditional styles ready too
  • support for Laravel DB Facade adding tag `property name="net.sf.jasperreports.data.adapter" value="laravel.sqlsrv"` on jrxml files or edit Default data adapter on report properties on JasperSoft Studio

  • Generic sample

    <?php
    
    use JasperPHP\Report;
    use JasperPHP\ado\TTransaction;
    use JasperPHP\ado\TLogger;
    use JasperPHP\ado\TLoggerHTML;
    
    //use \NumberFormatter;
    //use PHPexcel as PHPexcel; // experimental
    /**
     * classe TJasper
     *
     * @author   Rogerio Muniz de Castro <[email protected]>
     * @version  2018.10.15
     * @access   restrict
     * 
     * 2015.03.11 -- create
     * 2018.10.15 -- revision and internationalize, add TLogger classes
     * */
    class TJasper {
    
        private $report;
        private $type;
        private $param;
    
        /**
         * method __construct()
         * 
         * @param $jrxml = a jrxml file name
         * @param $param = a array with params to use into jrxml report
         */
        public function __construct($jrxml, array $param) {
            $GLOBALS['reports'] = array();
            $xmlFile = $jrxml;
            $this->type = (array_key_exists('type', $param)) ? $param['type'] : 'pdf';
            //error_reporting(0);
            $this->param = $param;
            $this->report = new JasperPHP\Report($xmlFile, $param); // $GLOBALS['reports'][$xmlFile];
            switch ($this->type) {
                case 'pdf':
                    JasperPHP\Instructions::prepare($this->report);
                    break;
                case 'xls':
                    JasperPHP\Instructions::setProcessor('\JasperPHP\XlsProcessor');
                    JasperPHP\Instructions::prepare($this->report);
                    break;
            }
        }
    
        public function outpage($type = 'pdf') {
            $this->report->generate();
            $this->report->out();
            switch ($this->type) {
                case 'pdf':
                    $pdf = JasperPHP\Instructions::get();
                    $pdf->Output('report.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(JasperPHP\Instructions::$objOutPut, 'Excel5');
                    $objWriter->save('php://output');
                    break;
            }
        }
    
        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 , (probaly in composer instalations)
    require('../../phpoffice/phpexcel/Classes/PHPExcel.php'); // point to tcpdf class previosly instaled , (probaly in composer instalations)
    //require('../TCPDF/tcpdf.php'); // point to tcpdf class previosly instaled , (probaly in stand alone instalations)
    // on production using composer instalation is not necessaty 
    
    $report_name = isset($_GET['report']) ? $_GET['report'] : 'testReport.jrxml';  // sql into testReport.txt report do not select any table.
    TTransaction::open('dev');
    TTransaction::setLogger(new TLoggerHTML('log.html'));
    $jasper = new TJasper($report_name, $_GET);
    $jasper->outpage();
    ?>

    Requirements

    • PHP 5.2+
    • "tecnickcom/tcpdf":"6.2.*"
    • "PHPOffice/PHPExcel" only of XLS export

    How to use this sample

    Define database conections params into file config\dev.ini
    View file src\ado\TConection.php to define database type
    Sample URL:
    http://localhost/vendor/quilhasoft/JasperPHP/TJasper.class.php?param1=foo&param2=bar
    URL params passed into URL are the params defined into xmlr file.

    Using composer

    Add "quilhasoft/jasperphp":"dev-master" into your composer config file and update/install

    Live samples

    • A basic test: Here
    • A burn test, 201 pages, hosted in a default hostgator server: Here
    • Brasilian payment method "boleto" in "carne":Here
    • Brasilian payment method "boleto" in A4 :Here
      ** Brasilian boleto project disponible in QuilhaSoft/JasperPHP-OpenBoleto.

    License

    • MIT License

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.