Justin_6 Posted March 21, 2014 Share Posted March 21, 2014 I'm using JasperServer Pro on Amazon MarketPlace and have 2 chart reports designed with Jasper Studio (and published to server.). In my PHP application, I'm using REST API php wrapper to call RunReport. My code is something like:$data = $rs->runReport($sample_report, 'html', NULL, NULL, $controls);I got an image back in the $data whose path is something like: /jasperserver-pro/rest_v2/reportExecutions/72034391_1395407813827_65/exports/html/attachments/img_0_0_0. Even after I added the host name to this URL, there is no image at that path.My question is how can I find the proper path for the image that needs to be accessible in my PHP application.P.S.When I ran the report from Jasper Server, it ran properly and the path for the chart image is something like. '/jasperserver-pro/reportimage?jrprint=1665740205_1395408153483_15&image=img_0_0_0', can I use path like this to access the chart image? how can I get those numbers in the URI?Thanks, Link to comment Share on other sites More sharing options...
grantbacon Posted March 25, 2014 Share Posted March 25, 2014 As of now, its not possible to include images embedded in a report using the PHP client in HTML format. The URIs you are seeing refer to some resources that require an authenticated session to view. One solution currently would be to host the images in a place accessible to the public (e.g: a separate web server). Naming the images as seen in the output and without a suffix, this should load the images. For example, if you request the image as below (note, I'm using latest github version, its unclear if youre using version from exchange, or github)$report = $c->reportService()->runReport("/reports/samples/AllAccounts", "html", null, "http://testprefix.com/images/");[/code]Then when images are added to the HTML, they'll have a src attribute with the prefix your provided:<img src="http://testprefix.com/images/img_0_46_0" style="position: absolute; left:145px; top: 22px;" alt="" title="JasperReports Logo"/></div></td><td>[/code] Link to comment Share on other sites More sharing options...
grantbacon Posted March 25, 2014 Share Posted March 25, 2014 If you are using an old version, just remove ->reportService(), and the argument order should be the same. Link to comment Share on other sites More sharing options...
magrom Posted March 25, 2015 Share Posted March 25, 2015 I have been struggling with the missing charts and images in the HTML report when using php client and here is a workaround I found:1. Render a report in xml format://Import report in XML format$reportXML = $c->reportService()->runReport('/Reports/Sample_Report', 'xml', null, null, $controls);[/code] 2. All images and charts are there embedded in base64 format, find them and extract to a string array://Find base64 images encoded in the XML file$docXML = new DOMDocument();$docXML->loadXML($reportXML); //mark the use of loadXML$imagesXML = $docXML->getElementsByTagName('image');$imagesBase64= array();foreach ($imagesXML as $image) { foreach($image->childNodes as $child) { if ($child->nodeName=='imageSource'){ $imagesBase64[]=$child->textContent; } }}[/code] 3. Render a report second time this time in the html format:$reportHTML=$c->reportService()->runReport('/Reports/Sample_Report', 'html', null, null, $controls);[/code] 4. Find all img src tags and exchange its content with base64 encoded images from xml document. For some reason in my case the DomDocuments fails to accept rendered HTML report so I used regular expression instead:$reportHTML2 = preg_replace_callback('#src=["']([^"']+)["']#', function($matches) use (&$imagesBase64) { return 'src="data:image/png;base64,'.trim(array_shift($imagesBase64).'"');}, $reportHTML);[/code]5. and this is it.echo $reportHTML2;[/code] Link to comment Share on other sites More sharing options...
pinkyjaiswal501 Posted August 24, 2016 Share Posted August 24, 2016 I followed your code and while running it, I still get my chart missing. But, while having two charts in my asper report, image get displayed but only one image is being displayed. I don't understand why is this happening so. Please, help me to fix this. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now