简体   繁体   English

如何使用js将html和css渲染到pdf

[英]How to render html and css to pdf with js

Hello I need to create a custom quote in pdf, I retrieve the data in js and send it in the html and I retrieve the html to send it in pdf except that no library supports css, I found a solution with HTML2CANVAS except it returns an image and I don't want that Hello I need to create a custom quote in pdf, I retrieve the data in js and send it in the html and I retrieve the html to send it in pdf except that no library supports css, I found a solution with HTML2CANVAS except it returns an图像,我不想要那个

        document.getElementById('generationPdf').onclick = e =>{
            e.preventDefault()
            if (index + 1 === 1) {
                let folder_id = document.location.pathname.substring(8)
                let objectForDevis =  arrayObject[0]

                axios({
                    method: 'post',
                    url: folder_id+'/generate-pdf',
                    data: {
                    objectForDevis
                    }
                }).then(function (response) {
                    if (response) {
                       
                        
                    }
                });
            }
        }

use jsPDF the following is an example usage I found on this website使用jsPDF以下是我在这个网站上找到的示例用法

html2canvas(document.body, {
    onrendered:function(canvas) {

        //Returns the image data URL, parameter: image format and clarity (0-1)
        var pageData = canvas.toDataURL('image/jpeg', 1.0);

         //Default vertical direction, size ponits, format a4[595.28,841.89]
        var pdf = new jsPDF('', 'pt', 'a4');

        //Two parameters after addImage control the size of the added image, where the page height is compressed according to the width-height ratio column of a4 paper.
        pdf.addImage(pageData, 'JPEG', 0, 0, 595.28, 592.28/canvas.width * canvas.height );

        pdf.save('stone.pdf');

    }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM