Guest User

Code Download file Google Drive

a guest
Apr 28th, 2020
106,098
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 1 0
  1. let jspdf = document.createElement("script");
  2. jspdf.onload = function () {
  3. let pdf = new jsPDF();
  4. let elements = document.getElementsByTagName("img");
  5. for (let i in elements) {
  6. let img = elements[i];
  7. console.log("add img ", img);
  8. if (!/^blob:/.test(img.src)) {
  9. console.log("invalid src");
  10. continue;
  11. }
  12. let can = document.createElement('canvas');
  13. let con = can.getContext("2d");
  14. can.width = img.width;
  15. can.height = img.height;
  16. con.drawImage(img, 0, 0, img.width, img.height);
  17. let imgData = can.toDataURL("image/jpeg", 1.0);
  18. pdf.addImage(imgData, 'JPEG', 0, 0);
  19. pdf.addPage();
  20. }
  21. pdf.save("Exported_File.pdf");
  22. };
  23. jspdf.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js';
  24. document.body.appendChild(jspdf);
Add Comment
Please, Sign In to add comment