Exemplo n.º 1
0
function getOutputFormat($format)
{
    $fmt = null;
    switch ($format) {
        case "pdf":
            $fmt = new java("org.eclipse.birt.report.engine.api.PDFRenderOption");
            $fmt->setOutputFormat("pdf");
            header("Content-type: application/pdf");
            break;
        case "html":
            $fmt = new java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
            $fmt->setOutputFormat("html");
            $ih = new java("org.eclipse.birt.report.engine.api.HTMLServerImageHandler");
            $fmt->setImageHandler($ih);
            header("Content-type: text/html");
            break;
        case "msword":
            $fmt = new java("org.eclipse.birt.report.engine.api.RenderOption");
            $fmt->setOutputFormat("doc");
            header("Content-type: application/msword");
            break;
        case "xls":
            $fmt = new java("org.eclipse.birt.report.engine.api.RenderOption");
            $fmt->setOutputFormat("xls");
            header("Content-type: application/vnd.ms-excel");
            break;
        default:
            die("unknown output format {$format}");
    }
    return $fmt;
}
<?php

header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=downloaded.pdf");
define("JAVA_HOSTS", "127.0.0.1:8080");
define("JAVA_SERVLET", "/JavaBridge/JavaBridge.phpjavabridge");
require_once "java/Java.inc";
session_start();
$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());
try {
    $report = $birtReportEngine->openReportDesign("{$here}/TopNPercent.rptdesign");
    $task = $birtReportEngine->createRunAndRenderTask($report);
    $taskOptions = new java("org.eclipse.birt.report.engine.api.PDFRenderOption");
    $outputStream = new java("java.io.ByteArrayOutputStream");
    $taskOptions->setOutputStream($outputStream);
    $taskOptions->setOption("pdfRenderOption.pageOverflow", "pdfRenderOption.fitToPage");
    $taskOptions->setOutputFormat("pdf");
    $task->setRenderOption($taskOptions);
    $task->run();
    $task->close();
} catch (JavaException $e) {
    echo $e;
    //"Error Calling BIRT";
}
//echo $outputStream;
echo java_values($outputStream->toByteArray());
Exemplo n.º 3
0
 * php report.php >helloBirt.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
$renderContext = new java("org.eclipse.birt.report.engine.api.HTMLRenderContext");
$renderContext->setBaseImageURL("{$here}/images");
$contextMap = new java("java.util.HashMap");
$CONTEXT = java("org.eclipse.birt.report.engine.api.EngineConstants")->APPCONTEXT_HTML_RENDER_CONTEXT;
$contextMap->put($CONTEXT, $renderContext);
// Load the report design
$design = $birtReportEngine->openReportDesign("{$here}/{$myReport}");
$task = $birtReportEngine->createRunAndRenderTask($design);
$task->setAppContext($contextMap);
// Add HTML render options
$options = new java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
$options->setOutputFormat($options->OUTPUT_FORMAT_HTML);
// Create the output
$out = new java("java.io.ByteArrayOutputStream");
$options->setOutputStream($out);
$task->setRenderOption($options);
$task->run();
$task->close();
// Return the generated output to the client
echo java_values($out);
<?php

header("Content-type: application/msword");
header("Content-Disposition: inline; filename=downloadedmsdoc.doc");
define("JAVA_HOSTS", "127.0.0.1:8080");
define("JAVA_SERVLET", "/JavaBridge/JavaBridge.phpjavabridge");
require_once "java/Java.inc";
session_start();
$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());
try {
    $report = $birtReportEngine->openReportDesign("{$here}/TopNPercent.rptdesign");
    $task = $birtReportEngine->createRunAndRenderTask($report);
    $taskOptions = new java("org.eclipse.birt.report.engine.api.RenderOption");
    $outputStream = new java("java.io.ByteArrayOutputStream");
    $taskOptions->setOutputStream($outputStream);
    $taskOptions->setOutputFormat("doc");
    $task->setRenderOption($taskOptions);
    $task->run();
    $task->close();
} catch (JavaException $e) {
    echo $e;
    //"Error Calling BIRT";
}
//echo "test";
//echo $outputStream->toString().trim();
echo java_values($outputStream->toByteArray());
$path_parts = pathinfo($pth);
$imageURLPrefix = $path_parts['dirname'] . "/sessionChartImages/";
require_once "java/Java.inc";
session_start();
$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());
try {
    $document = $birtReportEngine->openReportDocument($here . "/reportDocuments/" . session_id() . "/mytopnreportdocument.rptdocument");
    $lastPage = $document->getPageCount();
    $task = $birtReportEngine->createRenderTask($document);
    $taskOptions = new java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
    $outputStream = new java("java.io.ByteArrayOutputStream");
    $taskOptions->setOutputStream($outputStream);
    $taskOptions->setOutputFormat("html");
    $ih = new java("org.eclipse.birt.report.engine.api.HTMLServerImageHandler");
    $taskOptions->setImageHandler($ih);
    $taskOptions->setBaseImageURL($imageURLPrefix . session_id());
    $taskOptions->setImageDirectory($here . "/sessionChartImages/" . session_id());
    $taskOptions->setEnableAgentStyleEngine(true);
    $task->setRenderOption($taskOptions);
    //Note that top n report only has one page so this will return the same as not setting page number or range
    $task->setPageNumber($lastPage);
    //page range
    $task->setPageRange("1-1");
    $task->render();
    $task->close();
} catch (JavaException $e) {
    echo $e;
    //"Error Calling BIRT";
<?php

if (!get_cfg_var('java.web_inf_dir')) {
    define("JAVA_HOSTS", "127.0.0.1:8080");
    define("JAVA_SERVLET", "/JavaBridge/JavaBridge.phpjavabridge");
}
require_once "java/Java.inc";
$pth = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
$path_parts = pathinfo($pth);
$filePrefix = $path_parts['dirname'] . "/myreport.xls";
session_start();
$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());
try {
    $report = $birtReportEngine->openReportDesign("{$here}/TopNPercent.rptdesign");
    $task = $birtReportEngine->createRunAndRenderTask($report);
    $taskOptions = new java("org.eclipse.birt.report.engine.api.RenderOption");
    $taskOptions->setOutputFileName($here . "/myreport.xls");
    $taskOptions->setOutputFormat("xls");
    $task->setRenderOption($taskOptions);
    $task->run();
    $task->close();
} catch (JavaException $e) {
    echo $e;
    //"Error Calling BIRT";
}
echo 'Click <a href=' . $filePrefix . '>Here</a> to download your report';