Does ShieldUI support export to PDF functionality?

164 Views Asked by At

I want to use Shield UI charting tools in my project. And I need an export-to-PDF functionality too. Is there any method by which I can get the image of charts on server side so that I can use it to generate a PDF file?

1

There are 1 best solutions below

0
On

Shield Chart generates an image from SVG in the browser. You need to send the image data to your server, where it can be exported to PDF. Check this JSBIN out. It roughly demonstrates one possible approach. The steps to follow:

  1. Get the chart instance using javascript: var chart = $("#chart").swidget().
  2. Call chart.exportToImage() to render the chart as image.
  3. Wait 100ms for the image box to show and find the image source: $(".shield- lightbox").find("img").attr("src"). The image src is a base64-encoded string that contains the image data.
  4. Send the image data somehow to the server for exporting. In this particular example, I send it to http://pdfcrowd.com/ for demonstration. I can't use AJAX here, so I make a full page submit. The result is a JSON string with a URL that can be used to access the generated PDF.

Your server and PDF generation approach may be different, but the idea is to send the image data somehow so it can be converted to PDF.