Jump to content
Changes to the Jaspersoft community edition download ×

Justin_6

Recommended Posts

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

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

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

  • 11 months later...

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

  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...