L
L
ligisayan2018-09-25 19:57:21
JavaScript
ligisayan, 2018-09-25 19:57:21

How to save pictures and Cyrillic text from html page in pdf file?

Converting html page to pdf using javascript on the client side. I do this using the jspdf and html2canvas libraries according to the instructions from the video
But, unfortunately, this method does not save images (canvas) Here is my demo

function getPDF() {
    doCanvas();

    $(document).bind('function_a_complete', doPDF);
}

function doCanvas() {
    html2canvas(document.querySelector("#myDiv")).then(canvas => {
        document.querySelector("#newDiv").appendChild(canvas);
    });
    $(document).trigger('function_a_complete');
}
function doPDF() {

    console.log("do pdf");
    var doc = new jsPDF();
    doc.fromHTML($('#newDiv').html(), 20, 20, {'width':500});
    doc.text(50,50, "Новый текст");
    doc.save('test.pdf');
}

At the first click on the download PDF button (above), the picture is rendered, at the second - the info from the page is downloaded, but, as we see in the downloaded file, only text information is saved, and the Cyrillic letters are written in shorthand.
How can this be corrected? And of course, ideally, make sure that the page is downloaded from the first click.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question