jspdf 浏览器大小似乎影响 pdf 大小

jspdf browser size seems to effect pdf size

如果我使用 JsPDF 创建 pdf,浏览器大小似乎会影响 pdf 中文本的大小。创建 te pdf 的代码。

 var pdf = new jsPDF();

 //To split on multiple pages
 var options = {
      pagesplit: true
 }
 pdf.addHTML(document.getElementById("test"), options,function() {
      pdf.save('test.pdf');
 });

还有 html

<div id="pdf_container">
    <div id="pdf_top">
        <h1>My report</h1>
    </div>
   <div>
        <p>some text</p>
        <p>some text</p>  
        <p>some text</p>
        <p>some text</p>
        <p>some text</p>
        <p>some text</p>
    </div>  
</div>

link 到两者的结果 pdf.save: http://imgur.com/XyDPFFb

有人知道如何解决这个问题吗?

JsPDF 使用您发送给函数的 div 的当前大小。

您必须为要转换为 PDF 的每个元素指定固定的样式和大小,才能始终获得相同的文件。试试这个 css,您可以尝试不同的宽度和字体大小,直到获得您想要的样式。

myStlye.css

#pdf_container{
    width:500px;
    font-size:15px;
}