Clomez
Clomez

Reputation: 1512

Font size for footer, in jsPDF autoTable

So,

I've successfully modified everything else but can't figure how to change just the footers font size, it is now way too big compared to table font itself.

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

Footer itself is iterating nicely, page numbers show up as they are suppose to, but even if i pass options object into psd.text() as stated in documentation, it still wont change the font size.

Documentation for text

Upvotes: 3

Views: 11715

Answers (1)

Clomez
Clomez

Reputation: 1512

pdf.setFontSize(5);

and remember to put it before putting the text into footer,

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

Upvotes: 4

Related Questions