Guest User

Untitled

a guest
Jul 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public captureScreen() {
  2. var data = document.getElementById('contentToConvert');
  3.  
  4. html2canvas( data ).then(canvas => {
  5.  
  6. var imgWidth =297;
  7. var pageHeight = 210;
  8. var imgHeight = canvas.height * imgWidth / canvas.width;
  9. var heightLeft = imgHeight;
  10. const contentDataURL = canvas.toDataURL('image/png')
  11. var doc = new jspdf('l', 'mm', 'a4'); // A4 size page of PDF
  12. var position = 2;
  13. doc.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight)
  14.  
  15. var pdf =doc.output(); //returns raw body of resulting PDF returned as a string as per the plugin documentation.
  16. var data = new FormData();
  17. data.append("data" , pdf);
  18. var xhr = new XMLHttpRequest();
  19.  
  20. xhr.send(data);
  21. });
  22. }
  23.  
  24. uploadFile(data) {
  25. const file = data.target.files[0];
  26. const filePath = Date.now().toString();
  27. const fileRef = this.storage.ref('/test/' + filePath);
  28. const task = this.storage.upload('/test/' + filePath, file);
  29. this.uploadPercent = task.percentageChanges();
  30. task.snapshotChanges().pipe(
  31. finalize(() => {
  32. this.downloadURL = fileRef.getDownloadURL();
  33. this.downloadURL.subscribe(url => this.url = url
  34. )
  35.  
  36. }))
  37. .subscribe();
  38.  
  39. }
Add Comment
Please, Sign In to add comment