Web/JSP & JQuery
JS에서 html 파일 pdf로 저장하여 다운로드 하기
땀두
2020. 8. 10. 11:25
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js"></script>
<script>
html2canvas(여기에 원하는 html 태그 이름).then(function(canvas) {
var imgData = canvas.toDataURL('image/png');
var imgWidth = 210;
var pageHeight = 290;
var imgHeight = canvas.height * imgWidth / canvas.width;
var doc = new jsPDF({
'orientation': 'p',
'unit': 'mm',
'format': 'a4'
});
doc.addImage(imgData, 'PNG', 0, 0, imgWidth, imgHeight);
doc.save('result.pdf');
});
</script>
더 다른 옵션과 설명은 아래 참고
http://raw.githack.com/MrRio/jsPDF/master/docs/index.html
Home - Documentation
jsPDF Generate PDF files in client-side JavaScript. This is a fork of MrRios' jsPDF modified to work with svg2pdf.js, which converts SVG elements to PDF. Since version 2.0.0 this fork is fully compatible to the original version and comes with a large amoun
raw.githack.com