我正在使用jasper report iReport工具从数据库中生成一些报告。
全部完成后,我正在使用一个名为Lavela/jasperPHP的库通过API生成报告,并将其导出为pdf、xls。。。
我的问题是,我想在我网站的框架或容器中打开报告,现在的情况是,我可以将报告下载到pdf和xls,或者在html页面中打开报告但不能在我的网站模板中的iframe、容器或元素中打开。
有什么帮助吗?
这是我使用LARAVEL 5.1的PHP控制器
$output = public_path() . '/report/'.time().'_CancelAck';
$output = public_path() . '/report/'.time().'_CancelAck';
$ext = "pdf";
$data_file = public_path() . '/report/CancelAck.xml';
$driver = 'xml';
$xml_xpath = '/CancelResponse/CancelResult/ID';
'JasperPHP::process(
public_path() . '/report/report1.jrxml',
$output,
array($ext),
array(),
array(
'driver' => 'mysql',
'username' => 'root',
'password' =>'',
'host' => 'localhost',
'database' => 'test',
'port' => '3306',
),
array('data_file' => $data_file, 'driver' => $driver, 'xml_xpath' => $xml_xpath),
false,
false
)->execute();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.time().'_CancelAck.'.$ext);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Length: ' . filesize($output.'.'.$ext));
flush();
readfile($output.'.'.$ext);
unlink($output.'.'.$ext);
}
}
这是我的路线:
Route::get('/', function () {
return view('welcome');
});
Route::get('getreportService/','ReportController@getReport');
当我从url调用服务时,我会得到我想要的报告,但我需要在我的网站上显示这个报告。
您正在请求服务器创建可下载的内容。
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.time().'_CancelAck.'.$ext);
您需要为它找到合适的标头来返回html/css内容。