I can print a PDF with jsPDF but cannot use a div as content. For this I have now imported html2canvas, unfortunately I can't really figure out from the documentation how to use this. I have found a few instructions on the internet, but they did not work properly for me. The whole thing is in WordPress. I get various error messages, either that undefiend is not a function, or that it can't find something, or whatever.
first approach:
function testPDF() {
    console.log("testPDF-function works")
    html2canvas(document.getElementById('a4')).then(function(canvas){
        document.body.appendChild(canvas)
    })
    var img = canvas.toDataURL('img/png')
    var doc = new jsPDF();
    doc.addImage(img, 'JPEG', 20,20)
    doc.save('test.pdf');
}
second approach: Github (here someone has merged the two libraries, but that doesn't work for me either.)
let page = document.getElementById("a4");
function testPDF() {
    html2PDF(page, {
        jsPDF: {
            format: "a4",
        },
        imageType: "image/jpeg",
        output: "offerte.pdf",
    });
}
third approach
function testPDF() {
    html2canvas(document.getElementById("a4")).then(function cancas(canvas) {
        // document.body.appendChild(canvas);
        var doc = new jsPDF();
        doc.addImage(document.body.appendChild(canvas));
        doc.save("offerte.pdf");
    });
}
My html looks like this:
<div id='a4' style='height: 297mm; width: 210mm; border: 1px black solid; margin-left:20%;'>
    <p>Content</p>
</div>
<button id='pdfExport' onclick='testPDF' >Export PDF</button>"
 
    