【发布时间】:2016-04-28 16:16:23
【问题描述】:
我正在调用 BIRT 以通过 Java Bridge 生成 PDF 报告:
<?php
require_once("java/Java.inc");
class runReport {
function runReport($report, $param, $output) {
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=".$output.".pdf");
$report_name = RP_REPORT . $report;
$ctx = java_context()->getServletContext();
$birtReportEngine = java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($ctx);
java_context()->onShutdown(java("org.eclipse.birt.php.birtengine.BirtEngine")->getShutdownHook());
try{
$connect = new Java("connectDb");
$report = $birtReportEngine->openReportDesign($report_name);
$task = $birtReportEngine->createRunAndRenderTask($report);
foreach ($param as $key => $value) {
$task->setParameterValue($key, new java("java.lang.String",$value));
}
$taskOptions = new java("org.eclipse.birt.report.engine.api.PDFRenderOption");
$outputStream = new java("java.io.ByteArrayOutputStream");
$taskOptions->setOutputStream($outputStream);
$taskOptions->setOutputFormat("pdf");
$task->setRenderOption( $taskOptions );
$task->getAppContext()->put("OdaJDBCDriverPassInConnection", $connect->getConnection(SERVEUR, BDD_PORT, BDD, LOGIN_DB, PWS_DB));
$task->run();
$task->close();
} catch (JavaException $e) {
echo $e; //"Error Calling BIRT";
}
echo java_values($outputStream->toByteArray());
}
}
?>
除非$param 包含包含非ASCII 字符的参数,否则这工作正常。当$param 确实包含包含非ASCII 字符的参数时,不会生成报告。
$param的编码未知。
【问题讨论】:
-
你是说当
$birtReportEngine->openReportDesign($report_name);包含非ASCII时,结果不会返回到屏幕上?你会收到 500 错误吗? -
当发送到 BIRT 的参数包含非 ASCII 时,我无法打开 pdf 文件。
-
和
$report_name是文件名吗?那么当文件名包含非 ASCII 字符时呢? -
$report_name是具有 .rptdesign 扩展名的 BIRT 报告的文件名,即使此文件名包含所有 ASCII 字符也会出现问题。 -
但是你说“重音字母不能打开报告”!? “强调”是非 ASCII。你能澄清一下吗?
标签: java php character-encoding birt php-java-bridge