【问题标题】:Font size for footer, in jsPDF autoTable页脚的字体大小,在 jsPDF autoTable 中
【发布时间】:2019-05-13 13:00:33
【问题描述】:

所以,

我已经成功修改了其他所有内容,但不知道如何仅更改页脚字体大小,与表格字体本身相比,它现在太大了。

    let pdf = new jsPDF({orientation: 'l'});
    let res = pdf.autoTableHtmlToJson(document.getElementById('capture'));
    const totalPagesExp = '{total_pages_count_string}';
    let height = pdf.internal.pageSize.getHeight();

    const footer = function(res) {
        let str = 'Sivu ' + res.pageCount;

        if (typeof pdf.putTotalPages === 'function') {
            str = str + ' / ' + totalPagesExp;
            str = str + ' -- ' + moment().format('L').toString();
        }

        //PROBLEM GOES HERE
        pdf.text(str, 5, height - 5, {
            fontSize: 5
        });
    };

    pdf.autoTable(
        res.columns,
        res.data,
        {margin: {top: 25, bottom: 15},
        styles: {overflow: 'linebreak',
                fontSize: 6},
        showHeader: 'everyPage',
        afterPageContent: footer,
        theme: 'plain'});

    if (typeof pdf.putTotalPages === 'function') {
        pdf.putTotalPages(totalPagesExp);
    }

    pdf.save( 'file.pdf');

页脚本身迭代得很好,页码按预期显示,但即​​使我按照文档中的说明将选项对象传递给psd.text(),它仍然不会改变字体大小。

Documentation for text

【问题讨论】:

    标签: javascript pdf-generation jspdf jspdf-autotable


    【解决方案1】:
    pdf.setFontSize(5);
    

    记得把它放在之前把文字放到页脚,

            pdf.setFontSize(5);
            pdf.text(str, 5, height - 5, {
                styles: { fontSize: 5 },
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      相关资源
      最近更新 更多