1

BIRTとphpjavabridgeを使用してこのレポートを作成しました

<?php

header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=downloaded.pdf");

require_once("http://127.0.0.1:8080/JavaBridge/java/Java.inc");
header("Content-type: text/html");



// the report file to render
$myReport = "test.rptdesign";

// load resources, .rpt files and images from the current working dir
$here = getcwd();

$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());


// Create a HTML render context

try{

// Load the report design
$design = $birtReportEngine->openReportDesign("${here}/${myReport}");
$task = $birtReportEngine->createRunAndRenderTask( $design );
$task->setParameterValue("sample", new java("java.lang.String", "Hello world!"));

// Add HTML render options
$options = new java("org.eclipse.birt.report.engine.api.PDFRenderOption");
$options->setOutputFormat($options->OUTPUT_FORMAT_PDF);

// Create the output
$out = new java("java.io.ByteArrayOutputStream");
$options->setOutputStream($out);
$task->setRenderOption($options);
$task->run ();
$task->close();

} catch (JavaException $e) {
    echo $e; //"Error Calling BIRT";

}


// Return the generated output to the client
echo java_values($out->toByteArray());


?>

レポートは、Adobe Acrobatプラグインをトリガーしたため、InternetExplorer8.0内で完全に表示されました。問題は、MozillaFirefox3.5.4とGoogleChrome4.0.233内でレポートを開いたときに、Adobe Acrobatプラグインをトリガーする代わりに、PDFファイルのバイナリ文字列コンテンツが表示されたことです。

htdocフォルダーにpdfファイルを入れてFirefoxとChromeから呼び出すことでこれを確認しましたが、問題なく動作しました。しかし、なぜヘッダーがレポートで機能しないのでしょうか。

*また、ヘッダーがIE 8.0でのみ機能するのはなぜですか?レポートをすべての主要なブラウザで表示する必要があります

4

1 に答える 1

1

コンテンツ タイプは「application/pdf」にする必要があります

(または、最新の pdf 形式の場合は「application/x-pdf」)

変わればそう思う

header("Content-type: text/html");
to
header("Content-type: application/pdf");

上記のコードでは、上記のブラウザーは pdf ドキュメントのレンダリングを適切に開始する必要があり (そのように構成されている場合)、IE は正常に動作し続けます (IE には自動 MIME タイプ検出(コンテンツの最初の数百バイトに基づく) があります)。複雑な祝福です...)

于 2009-10-29T06:36:07.100 に答える