首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JASPERPHP仍然与Laravel 8一起工作吗?

JASPERPHP仍然与Laravel 8一起工作吗?
EN

Stack Overflow用户
提问于 2021-04-08 10:17:47
回答 1查看 2.5K关注 0票数 0

我目前正在使用cossou/JasperPHP,在生成pdf文件时遇到了问题。它一直给我这个错误-- Your report has an error and couldn't be processed! Try to output the command using the function输出();and run it manually in the console. --我尝试将->execute()更改为->output() --它给了我一个错误,它找不到一个pdf文件。

还有其他像水晶报告或Jaspersoft那样的打印和制作报告的建议吗?

代码语言:javascript
复制
public function dbConfig(){
        //JasperPHP::compile(base_path('/vendor/cossou/jasperphp/examples/hello_world.jrxml'))->execute();
        $jdbc_dir = 'D:\xampp\htdocs\TestTO\vendor\cossou\jasperphp\src\JasperStarter\jdbc';
        return [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST'),
            'port' => env('DB_PORT'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'database' => env('DB_DATABASE'),
            'jdbc_driver' => 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
            'jdbc_url' => 'jdbc:sqlserver://localhost:1433;databaseName=Employee;DataSource=(local)',
            'jdbc_dir' => $jdbc_dir
        ];
    }

    public function generateReport(){
        $jasper = new JasperPHP;

        $extension = 'pdf';
        $name = 'Employee';
        $filename = $name . time();
        $output = base_path('/public/reports/' .$filename);
        // JasperPHP::compile(storage_path('app/public'). '/reports/Employee.jrxml')->execute();

        $jasper->process(
            storage_path('app/public/reports/Employee.jasper'),
            $output,
            array($extension),
            array('id' => 1014),
            $this->dbConfig(),
            "pt_BR"
        )->execute();

        $file = $output . '.' . $extension;

        if(!file_exists($file)){
        }
        if($extension == 'xls'){
            header('Content-Description: Arquivo Excel');
            header('Content-Type: application/x-msexcel');
            header('Content-Disposition: attachment; filename="'.basename($file).'"');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));
            flush(); // Flush system output buffer
            readfile($file);
            unlink($file) ;
            die();
        }
        else if($extension == 'pdf')
        {
            return response()->file($file)->deleteFileAfterSend();
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-08 11:45:17

是的,对我来说,在拉拉8,它工作得很好.

我做了composer require cossou/jasperphp

然后进去

文件config/app.php

代码语言:javascript
复制
<?php
//...
'providers' => [
    //...
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,

    //insert jasper service provider here
    JasperPHP\JasperPHPServiceProvider::class
],

在web.php内部,我添加了

代码语言:javascript
复制
 use JasperPHP\JasperPHP as JasperPHP;


     Route::get('/java', function () {
    
            $jasper = new JasperPHP;
        
            // Compile a JRXML to Jasper
          $t=  $jasper->compile( '/home/midhun/hi/hello.jrxml')->execute();
         
        var_dump($t);
     
            // Process a Jasper file to PDF and RTF (you can use directly the .jrxml)
            $jasper->process(
                '/home/midhun/hi/hello.jrxml',
                false,
                array("pdf", "rtf"),
                array("php_version" => "8.0.3")
            )->execute();
        
            // List the parameters from a Jasper file.
            $array = $jasper->list_parameters(
                '/home/midhun/hi/hello.jrxml'
            )->execute();
            var_dump($array);
            return view('welcome');
        });

运行php个人服务后

并在浏览器本地主机中打开:8000/java

我拿到了pdf文件

而pdf是

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67001931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档