Jump to content

How to export image of UniMap for Report PDF


Alex S

Recommended Posts

Hi,

I'm trying to export an image from UniMap or UniHTMLFrame (e.g. with Google Maps)  to .png to use in a PDF report.

only produces a PDF of and empty map and the controls, but not the actual map in the exported .png

Using the external app, on a basic javascript map, wkhtmltopdf/wkhtmltoimage also only produces a blank image.

Any suggestions to do this in a Delphi UniGUI Web application?

Thanks

Link to comment
Share on other sites

Thanks Sherzod,

yes I was looking at this demo and the other Printscreen tagged articles on this forum, but implementing them, none produced an image containing the content of the web maps from the UniMap component.

After more research I found a solution. The {useCORS: true} entry needs to be added to the solution of freedowsRoO above, and then it works for me.

   UniMap1.JSInterface.JSCode(
    'html2canvas(document.querySelector("#'+ UniMap1.JSId +'"),{useCORS: true}).then(function(canvas) {'+
    'ajaxRequest('#1',"getData",["base64Data="+canvas.toDataURL()])});');

Here is more information.
https://stackoverflow.com/questions/46281261/google-map-is-not-displayed-when-using-html2canvas

It might not work on all browsers though.

  • Like 1
Link to comment
Share on other sites

Indeed, it works very well, tested using latest Chrome on Windows and Edge.

I wrote some code to convert the base64 data to .png file.

One more thing that was not clear in previous threads was to add a relative path reference to html2canvas.js under the CustomFiles property of the UniServerModule

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...