Jump to content
Changes to the Jaspersoft community edition download ×

how to Integrate jasper report in codeigniter?


Recommended Posts

  • 3 weeks later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 years later...
  • 3 years later...

Posible solución https://blog.linuxitos.com/post/codeigniter-3-jaspersoft-rest-client

En el archivo descargado de codeigniter instalar desde composer

composer require jaspersoft/rest-client[/code]

Una vez instalado crear un archivo helper con la función de reporte de la siguiente manera:

<?phprequire_once "vendor/autoload.php";use JaspersoftClientClient; function reporte($idRegistro, $name, $params, $type = 'pdf'){    $ci = &get_instance();    try {        $client = new Client('http://localhost:8080/jasperserver', 'jasperadmin', 'jasperadmin');        $report = $client->reportService()->runReport('/reports/'.$name, $type, null, null, $params);        $nombre_temporal = str_replace('/', '_', $name).'_'.$idRegistro.'.'.$type;        $config['upload_path']      = './files/reports/';        /* $config['max_size']      = '1000000';        $config['max_width']        = '10240000000';        $config['max_height']       = '76889';        $config['encrypt_name']     = true;        $config['allowed_types']    = 'jpg|jpeg|png|gif|pdf';        $config['file_name']        = $nombre_temporal; */        write_file($config['upload_path'].$nombre_temporal, $report);        return 'files/reports/'.$nombre_temporal;    } catch (Throwable $error) {        return 'error '.$error;    }}[/code]

Para usarlo desde el controaldor sería de la siguiente manera:

<?phpdefined('BASEPATH') OR exit('No direct script access allowed');class JasperReport extends CI_Controller {    public function __construct(){        parent::__construct();        $this->load->helper('reports');        $this->load->library('session');    }    public function index()    {        $params = [            'nombre_movimiento' => 'Reporte uno',            'autoriza' => '',            'cargo' => '',        ];        $data['pdf'] = reporte(1, 'Codeigniter/reporteuno', $params, 'pdf');        $this->load->view('report', $data);    }}[/code]

En la vista sería de éste modo:

[...]        <div class="row">            <div class="col-md-12 mt-4">                <h2>Test jasper reports</h2>                <p>                    PDF: <a href="<?=base_url($pdf);?>" target="_blank"><?=base_url($pdf);?></a>                </p>            </div>        </div>        <div class="row">            <div class="col-md-12">                <embed src="<?=base_url($pdf);?>" type="application/pdf" width="100%" height="600px"/>            </div>        </div>[...][/code]

Ajustar los enlaces o configuraciones de acuerdo a su proyecto.






Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...