无法在JSPDF中获得选择值

问题描述 投票:0回答:1

我正在尝试将HTML页面另存为PDF

domtoimage.toPng(document.getElementById('PrintForm')).then(function(blob){var pdf = new jsPDF('p','pt',[$('#PrintForm')。width(),$('#PrintForm')。height()]);                pdf.addImage(blob, 'PNG', 0, 0, $('#PrintForm').width(), $('#PrintForm').height());
                pdf.save("test.pdf");

                that.options.api.optionsChanged();
            });</pre>

在这种情况下,当我另存为pdf时,我无法获取我的选择标签值,我将在选择标签中获得默认值。如下所示enter image description here

javascript jquery jspdf
1个回答
0
投票

尝试一下...

var obj = $(".yourclassname")[0]

    var srcwidth = obj.scrollWidth;

    var pdf = new jsPDF('p', 'pt', 'a4');
    pdf.html(obj, {
        html2canvas: {
            scale: 600 / srcwidth
            //600 is the width of a4 page. 'a4': [595.28, 841.89] 
        },
        callback: function () {
            window.open(pdf.output('bloburl'));
        }
    });        

您的类名是页面中的对象(或#yourobjectid)。 srcwidth是宽度计算,因此您的html适合页面的宽度。您可能需要在html中添加一些填充以适合pdf(我在div中添加了20px)。您应该使用jsPdf的1.5.3版才能使以上功能正常工作。希望这会有所帮助(对我来说确实有用)。您还应该使用最新版本的html2canvas 1.0.0-rc.5

© www.soinside.com 2019 - 2024. All rights reserved.