我目前正在使用 cossou/JasperPHP,但在生成 pdf 文件时遇到问题。它只是一直给我这个错误Your report has an error and couldn't be processed! Try to output the command using the function
output(); and run it manually in the console.
我尝试将 to 更改->execute()
为->output()
,它给了我找不到 pdf 文件的错误。
还有其他用于打印和制作报告的软件包建议,例如 Crystal Report 或 Jaspersoft?
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();
}
}