Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Problem with image-path with php/Javabridge
iparker
Hello,
I have a problem with the output of images in my report on the webserver. I’m working with birt over the php-javabridge. The problem is that the images are placed outside of the document-root of the apache webserver, so I tried the access to the images with the server-side-path to the files.
For testing the output of images I just insert different simple image-variants with a hard-coded URL-filename in my report. These variants are:
complete_absolute_path/filename.jpg
../../complete_relative_path/filename.jpg
But unfortunately no of these variants works. So how can I access these images? Is this possible via URL?
Any help would be great! I really get desperated about this problem...
Thanks!
Timo
Find more posts tagged with
Comments
JasonW
Timo,
Are these images created by BIRT or just images you wish to inlcude in the report? What render options are you setting for image handling?
Jason
iparker
Hello Jason,
Thanks a lot for your response!
I just wish to include existing images in my report. I set the following task and image-options:
$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);
Do you know how to set a shared resource that works on a linux-machine or rather how to set this shared resource with the php/javabridge?
Thanks again for your answer!
Best regards,
Timo
JasonW
Timo,
If you are using the HTMLServerImageHandler you need to set an image directory. This tells the BIRT engine where to put the images while generating the report. (This is not put in the img src tag)
$taskOptions->setImageDirectory($here . "/sessionChartImages/" . session_id());
Next you specify a base image url that is put in the img src tag.
$taskOptions->setBaseImageURL($imageURLPrefix . session_id());
You can also use HTMLCompleteImageHandler which puts full file based paths in the img src tag.
On the shared resource are your referring to a library or just setting the resource folder? Take a look at this example to set the resource folder:
<?php
define ("JAVA_HOSTS", "127.0.0.1:8080");
define ("JAVA_SERVLET", "/JavaBridge/JavaBridge.phpjavabridge");
$pth = "
http://"
; . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$path_parts = pathinfo($pth);
$imageURLPrefix = $path_parts ."/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{
//should only be set once will affect all users of the engine
$birtReportEngine->getConfig()->setResourcePath(${here} . "/birtreportlib" );
$report = $birtReportEngine->openReportDesign("${here}/uselib.rptdesign");
$task = $birtReportEngine->createRunAndRenderTask($report);
$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());
$task->setRenderOption( $taskOptions );
$task->run();
$task->close();
} catch (JavaException $e) {
echo $e; //"Error Calling BIRT";
}
echo $outputStream;
?>
Jason
iparker
Hello Jason,
I’m really really thankful for your answer!
To include images which are stored outsite of the document root from the apache webserver I done the following steps:
// Set the resource-path
$birtReportEngine->getConfig()->setResourcePath("absolute_path");
// Set BaseImageURL and ImageDirectory with the default-values
$taskOptions->setBaseImageURL($imageURLPrefix . session_id());
$taskOptions->setImageDirectory($here . "/sessionChartImages/" . session_id());
The images in the report are simply includes with the “shared recource” option and just the filename.
So I got one more question: In the html-output I works well. But for the pdf-output it does not work when I call the functions setBaseImageURL() and setImageDirectory() as denoted above. Is it right? Could you reproduce this behaviour?
Thanks again!!!
Timo
JasonW
You should not have to set this for PDF as images are embedded in the PDF. Can you try to import the image into the report as an embedded image? Right click on the embedded images icon in the outline view and select add. This will base64 encode the image in the report. Next add a image report item to the report and set it to the embedded image. Try running your report to pdf. If this does not work then it may be a file permission problem on the temp directory.
Jason
iparker
Hello Jason,
thanks again for your answer. Maybe there was a misunderstanding: The output of the images in the pdf works. It just don?t works if I call the setBaseImageURL() and the setImageDirectory() in the script. In this case I don?t get an error message but just no pdf-output file.
So everything is good ;-).
Timo
JasonW
Timo,
Setting the base image url and image directories are for the HTML emitter only.
Jason