How to download current screen as PDF and Image using html2canvas JS?

Liz.

I want to download the current screen as a PDF/Image using html2canvas.js.

1) Download current Screen as image The following code is working fine for me.

HTML

<head>
  <script src="html2canvas.js"></script>
  <script src="jquery.min.js"></script>
</head>
<body>
   <button onclick="download()" class="btn btn-danger">Download</button>
</body>

JS

function download(){
  html2canvas(document.body, {
    onrendered: function(canvas) {
      var a = document.createElement('a');
      a.href = canvas.toDataURL("image/jpeg");
      a.download = $.now()+'.jpg';
      a.click();
    }
  });
}

2) Download current screen as PDF How to implement this using html2canvas.js? How can I download and save the current screen as PDF?

Kindly help. Thank you!

Joomler

I have seen that html2canvas wont work with pdf download. But tehre is a tool called JsPDF

try this -

HTML Code

<canvas id="canvas" width="480" height="320"></canvas> 
<button id="download">Download Pdf</button>

JS code

html2canvas($("#canvas"), {
    onrendered: function(canvas) {         
        var imgData = canvas.toDataURL(
            'image/png');              
        var doc = new jsPDF('p', 'mm');
        doc.addImage(imgData, 'PNG', 10, 10);
        doc.save('sample-file.pdf');
    }
});

jsfiddle: http://jsfiddle.net/p4s5k59s/490/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to download current screen as PDF and Image using html2canvas JS?

From Dev

The ability to download an d3.js overlay on a google map using html2canvas

From Dev

How can I download content of div using html2canvas and FileSaver in the dowllaods folder instead of in the browser?

From Dev

How to put and download the content of a div in html into pdf file using JS?

From Dev

Download canvas image using JS Jquery

From Dev

convert html with highcharts graph to image using html2canvas

From Dev

Saving Morris charts to image using HTML2CANVAS

From Dev

Saving Morris charts to image using HTML2CANVAS

From Dev

Making a proper image capture of Current screen using jquery Or PHP or Convert div to pdf

From Dev

How to save html2canvas image into System Folder in jquery

From Dev

How to save html2canvas image into System Folder in jquery

From Dev

how to download the div tag description in image format using js

From Dev

Google Map screen capture is not working for marker and marker cluster using html2canvas

From Dev

Google Map screen capture is not working for marker and marker cluster using html2canvas

From Java

Vue/HTML/JS how to download a file to browser using the download tag

From Dev

Using html2canvas to render a highcharts chart to pdf doesn't work on IE and Firefox

From Dev

Empty PDF report is generated when we have multiple graphs using html2canvas and jsPDF library

From Java

How to download image using requests

From Dev

how to use html2canvas and jspdf to export to pdf in a proper and simple way

From Dev

How to download image/pdf file from database using Gridview's linkbutton?

From Dev

Prevent PDF auto download by idm using pdf.js

From Dev

How to replace image in canvas using kinetic js

From Dev

Create and download PDF using html2pdf with AngularJS

From Dev

Text alignment changes on exporting d3js chart svg as png using html2canvas

From Dev

how to download pdf using NodeJS and send it to the client?

From Dev

How to download a pdf file using ExtJS 4.2.1?

From Dev

How to Download a pdf Using the response from service

From Dev

html2canvas not capturing image

From Dev

html2canvas crop image on click

Related Related

  1. 1

    How to download current screen as PDF and Image using html2canvas JS?

  2. 2

    The ability to download an d3.js overlay on a google map using html2canvas

  3. 3

    How can I download content of div using html2canvas and FileSaver in the dowllaods folder instead of in the browser?

  4. 4

    How to put and download the content of a div in html into pdf file using JS?

  5. 5

    Download canvas image using JS Jquery

  6. 6

    convert html with highcharts graph to image using html2canvas

  7. 7

    Saving Morris charts to image using HTML2CANVAS

  8. 8

    Saving Morris charts to image using HTML2CANVAS

  9. 9

    Making a proper image capture of Current screen using jquery Or PHP or Convert div to pdf

  10. 10

    How to save html2canvas image into System Folder in jquery

  11. 11

    How to save html2canvas image into System Folder in jquery

  12. 12

    how to download the div tag description in image format using js

  13. 13

    Google Map screen capture is not working for marker and marker cluster using html2canvas

  14. 14

    Google Map screen capture is not working for marker and marker cluster using html2canvas

  15. 15

    Vue/HTML/JS how to download a file to browser using the download tag

  16. 16

    Using html2canvas to render a highcharts chart to pdf doesn't work on IE and Firefox

  17. 17

    Empty PDF report is generated when we have multiple graphs using html2canvas and jsPDF library

  18. 18

    How to download image using requests

  19. 19

    how to use html2canvas and jspdf to export to pdf in a proper and simple way

  20. 20

    How to download image/pdf file from database using Gridview's linkbutton?

  21. 21

    Prevent PDF auto download by idm using pdf.js

  22. 22

    How to replace image in canvas using kinetic js

  23. 23

    Create and download PDF using html2pdf with AngularJS

  24. 24

    Text alignment changes on exporting d3js chart svg as png using html2canvas

  25. 25

    how to download pdf using NodeJS and send it to the client?

  26. 26

    How to download a pdf file using ExtJS 4.2.1?

  27. 27

    How to Download a pdf Using the response from service

  28. 28

    html2canvas not capturing image

  29. 29

    html2canvas crop image on click

HotTag

Archive