Skip to content

Adding page numbers to pdf generated from html #3574

@speedDaemonAmber

Description

@speedDaemonAmber

I have read and understood the contribution guidelines.

I am trying to find a way to display page numbers within the header of my pdf, which is generated from a react component , as shown below.

        const pdf = new jsPDF('p', 'pt', 'a4');

        let data = await ReactDOMServer.renderToString(<PrintStatement />);

        pdf.html(data, {
            callback: function (pdf) {
                pdf.save(filename)
            }
        });

This component contains a header, as shown below. In previous versions you could add a span with class='pageCounter' and a page number would be displayed in that span. This does not seem to be working in the latest version. I have also tried putting it in the footer, but it will not display there either. Is there a way to accomplish this in the latest version?

		<header className='pdf-header'>
			<p className='date'>{currentDate}</p>
			<p className='title'>Ledger Report - Current Transactions</p>
			<p className='page'>Page <span className='pageCounter'></span></p>
		</header>

An example of the resulting pdf is attached.

PaymentHistory.pdf

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions