FoxInCloud
screen to image
Gravatar is a globally recognized avatar based on your email address. screen to image
  Vincent H.
  All
  Mar 19, 2021 @ 02:34am

Hi Thierry,

I'm trying to copy the contents of a screen into an image (or better, a PDF)
For that, I of course use the html2canvas library, but I get "canvas.toDataURL is not a function"
Here is my code, in the click() of a button:

IF (Type('m.thisForm.wlHTMLgen') == 'L' AND m.thisForm.wlHTMLgen)
   LOCAL lcJS
   TEXT TO lcJS TEXTMERGE NOSHOW FLAGS 1 PRETEXT 3
      var container = jQuery("#<<THISFORM.wcID>>")
      html2canvas(container, { allowTaint: true });
      {onrendered: jQuery(function (canvas) {
      var link = document.createElement("a");
      document.body.appendChild(link);
      link.download = "html_image.png";
      link.href = canvas.toDataURL("image/png");
      link.target = '_blank';
      link.click();
      })};
   ENDTEXT
   RETURN m.lcJS
ENDIF

A little help ? Thanks in advance

Gravatar is a globally recognized avatar based on your email address. re: screen to image
  FoxInCloud Support - Thierry N.
  Vincent H.
  Mar 20, 2021 @ 05:33am

Hi Vincent,

html2canvas() accepts 2 arguments:

  1. the HTML element (not a jQuery object)
  2. an options object

here is a sample code built by modify class awfrmfb of aw method init

html2canvas(jQuery('#Window_modal_scx').get(0) || jQuery('.Window_modal_scx').get(0)
, {onrendered: function(canvas){ /* options object */
  jQuery(canvas).css({width:'100%'});
  jQuery('#awfrmfb-cntscreenshot').html(canvas);
  }
});

Here is the full html2canvas() options documentation

Gravatar is a globally recognized avatar based on your email address. re: screen to image
  Vincent H.
  FoxInCloud Support - Thierry N.
  Mar 20, 2021 @ 06:16am

not a jQuery object

Thanks Thierry, I will try to carry on with your lights ...

Gravatar is a globally recognized avatar based on your email address. re: screen to image
  Vincent H.
  FoxInCloud Support - Thierry N.
  Mar 20, 2021 @ 09:01am

With jQuery("#<<THISFORM.wcID>>").get(0) it's fine !

Thanks again

Gravatar is a globally recognized avatar based on your email address. re: screen to image
  Vincent H.
  Vincent H.
  Mar 20, 2021 @ 09:25am

Just a question more:

What do you think about jsPDF library ? Do you use it ?

Gravatar is a globally recognized avatar based on your email address. re: screen to image
  FoxInCloud Support - Thierry N.
  Vincent H.
  Mar 21, 2021 @ 01:11pm

No, so far I've never used the jsPDF library.

© 1996-2021