【问题标题】:can't able to get the select value in JSPDF无法在 JSPDF 中获取选择值
【发布时间】:2020-08-11 21:36:38
【问题描述】:

我正在尝试将我的 html 页面保存为 PDF

domtoimage.toPng(document.getElementById('PrintForm'))
                .then(函数(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 时获取我的选择标签值,我将在选择标签中获得默认值。如下所示

【问题讨论】:

    标签: javascript jquery jspdf


    【解决方案1】:

    试试这个...

    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'));
            }
        });        
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 2021-06-29
      • 2020-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多