I'm attemping to build a PHP client that displays HTML reports. My reports looks fine when they are exported to PDF, for example. Only when displaying the report in HTML format in the browser, the images are missing. I am using the PHP client provided on this site to fetch the report:
$FullReport = $client->runReport($uri, 'html', null, $controls);
I then dump out $FullReport to my browser, which produces the above issue. I noticed that the HTML references relative paths, so I have tried to point directly to the JasperServer resources, without any luck:
$patterns = array();
$patterns = '/src=\'/';
$patterns = '/src="/';
$replacements = array();
$replacements = 'src=\'http://address:port';
$replacements = 'src="http://address:port';
$FullReport = preg_replace($patterns, $replacements, $FullReport);
I also found that when I login in the browser directly, and then invoke the report, the images will show (because it fetches the images directly from the JasperServer, bypassing my Tomcat server):
Moreover, when I do this within the same browser window, my above workaround does work! But it all depends on having logged in in the same browser window first.
Can anyone provide any idea on how I can progress with this issue?
I was hoping a more sophisticated solution would dawn, but alas, hopefully the following is of use to anyone in the future:
I have now resolved this issue by moving the image directly to my web server, rather than embedding it in the report. In the iReport Designer I have set the ImageExpression property to point directly to this image (the image location surrounded with double quotes) and I have set the Is Lazy property to true to ensure that the image on my web server is referenced when the report is executed.
I'm still a little worried that I have to go back and manually edit all my reports if my host address should change in the future, so if anyone can drop some hints on whether or not this can be made configurable, that would be much appreciated. Otherwise this solution works like a charm.
Along with your inputControls, try adding:
$controls['attachmentsPrefix'] = 'http://url.to.report.attachments/prefix/';
This should prefix any attachment within the HTML of the report with the URL provided, so the data isnt' being pulled from the report server but from a webserver. I haven't tested this though, so let me know how it goes