Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
JavaBridge: Php Render PDF from rptdocument
lonhro
Hi All
I am currenly reviewing functionality for the PHP JavaBridge. There are examples that illustrate the various Run AND Rendering tasks that are available. I have noted that there is a PhpRenderHTML task which renders a HTML document from an rptdocument but no PhpRenderPDF. There is a PhpRunAndRenderPdF which will execute a rptdesign and render as pdf.
Is it possible to render a PDF from a rptdocument or do you always need to run the rptdesign and render the PDF as part of the same task.
We are developing a system that will pregenerate reports and I would like to generate rptdocuments and then render HTML or PDFs from these. Currently, it seems we will need to pregenerate rptdocuments and PDF documents which is not ideal from a storage persective.
Thanks
Find more posts tagged with
Comments
JasonW
Sure you can render a rptdocument in pdf. Just replace this:
$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());
with
$taskOptions = new java("org.eclipse.birt.report.engine.api.PDFRenderOption");
$outputStream = new java("java.io.ByteArrayOutputStream");
$taskOptions->setOutputStream($outputStream);
$taskOptions->setOutputFormat("pdf");
Jason
lonhro
Jason
Thanks for your response. I did get it working alright. I had a few of the options specified incorrectly. The full php is below:
<?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{
$document = $birtReportEngine->openReportDocument($here . "/reportDocuments/" . session_id() . "/mytopnreportdocument.rptdocument");
//$document = $birtReportEngine->openReportDocument($here . "/reportDocuments/" . session_id() . "/simple.rptdocument");
$task = $birtReportEngine->createRenderTask($document);
$taskOptions = new java("org.eclipse.birt.report.engine.api.PDFRenderOption");
$taskOptions->setOutputFormat("pdf");
//$taskOptions->setOutputFilename("test.pdf");
$outputStream = new java("java.io.ByteArrayOutputStream");
$taskOptions->setOutputStream($outputStream);
$task->setRenderOption( $taskOptions );
$task->render();
$task->close();
} catch (JavaException $e) {
echo $e; //"Error Calling BIRT";
}
echo java_values($outputStream->toByteArray());
?>