Сначала вы должны добавить скрипт в ваш index.html для импорта jsPdf и html2canvas:
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
Вторая попытка конвертировать HTML в холст:
$(document).ready(function(){
$('#buttons').click(function () {
html2canvas(document.getElementById('inputext')).then((canvasObj)=> {
startPrintProcess(canvasObj, 'report',function (){});
});
});
function startPrintProcess(canvasObj, fileName, callback) {
var pdf = new jsPDF('p', 'mm', 'a4'),
pdfConf = {
pagesplit:false,
background: '#fff',
};
document.body.appendChild(canvasObj); //appendChild is required for html to add page in pdf
pdf.addHTML(canvasObj, 5, 5, pdfConf, function() {
document.body.removeChild(canvasObj);
// pdf.addPage();
pdf.save(fileName + '.pdf');
callback();
});
}
});