0

I'm new here. I mainly deal with backend programming (OOP PHP) but I also have to do some frontend stuff. I'm currently working on creating a PDF (client side) with html2canvas and pdfmake. In this PDF I have to include 2 dynamically loaded graphics (canvas js), table and map (leaflat js). So far everything went well (I did everything else) but I do not know how to add the second graphic to my PDF.

CODE:

html2canvas($("#chartdiv"), {
   onrendered: function(canvas) {
   var myImage = canvas.toDataURL("image/png");
   //here i can add table, map and variable myImage to my docdefinition content and call pdfMake.createPdf(docDefinition).download(); to download the pdf.
   }
});
//i want to use variable myImage here.

This work fine, but how i can use variable myImage outside the function to add in my docdefinition content to create my pdf with pdfmake? I'm trying to define global variable but not work. I do not use jspDF because I can not use Cyrillic there and my PDF contains Cyrillic.

Thanks a lot for the help!

stefo91
  • 618
  • 6
  • 16

1 Answers1

0

you assigned the var inside the function,better You’ll have to assign it that can accessible from the outside.

var myImage;

html2canvas($("#chartdiv"), {
   onrendered: function(canvas) {
   myImage = canvas.toDataURL("image/png");
   //here i can add table, map and variable myImage to my docdefinition content and call pdfMake.createPdf(docDefinition).download(); to download the pdf.
   }
});
Rp9
  • 1,955
  • 2
  • 23
  • 31
  • Thanks, but i try this and don't work. When i assigned the var otside the function like this "var myImage = null" and then i add alert(myImage) after function the result is null. – stefo91 May 11 '18 at 12:17