Created
September 12, 2019 15:21
-
-
Save jainofcsubham/4a19f304fe79e97f24aa601f8822ba80 to your computer and use it in GitHub Desktop.
Client side PDF generation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param element The element that triggered this function. | |
* Downloads the results summary in PDF format. | |
*/ | |
function downloadPDF(element) { | |
var orientation = 'l'; | |
var left = 25 | |
const filename = 'TrustedTechTeam-WSEstimate.pdf'; | |
var html = $('.results').html(); | |
var divHeight = $('.results').height(); | |
var divWidth = $('.results').width(); | |
var ratio = divHeight / divWidth; | |
var temp = document.createElement("div"); | |
temp.classList.add("positioning"); | |
temp.classList.add("results"); | |
$('.page').append(temp); | |
temp.innerHTML = html; | |
if($(window).width() <= 1024){ | |
orientation = 'p'; | |
left = 10 | |
} | |
html2canvas( $('.positioning'), { | |
useCORS: true, | |
scale: 2, | |
dpi: 300, | |
onrendered:function(canvas) { | |
let pdf = new jsPDF(orientation, 'mm', 'letter'); | |
var width = pdf.internal.pageSize.getWidth(); | |
var height = pdf.internal.pageSize.getHeight(); | |
height = ratio * width; | |
pdf.addImage(canvas.toDataURL('image/jpeg'), 'JPEG', 50, 60, width-140, height-100); | |
pdf.save(filename); | |
$('.positioning').remove(); | |
} | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment