jsでPDF出力する方法
- 公開日:
- 更新日:
- 文字数:510文字
const button = document.getElementById('pdf-btn')
button.addEventListener('click', (event) => { const source = document.getElementById('display-pdf') html2canvas(source,{ backgroundColor: '#FFFFFF', scale : 4 }).then(capture => { //document.body.appendChild(capture)
const imgData = capture.toDataURL('image/png') const doc = new jsPDF() const width = doc.internal.pageSize.width doc.addImage(imgData, 'PNG', 10, 10, width * 0.9, 0)
doc.save("sample.pdf") }) })