Hi,
I’m using ERPNext/Frappe v16.35.0 with the standard wkhtmltopdf PDF generator.
My wkhtmltopdf version is:
wkhtmltopdf 0.12.6.1 (with patched qt)
I have a custom Sales Invoice Print Format with a bank footer. I need this footer to appear on every page of the generated PDF.
I initially used a normal HTML element:
<div class="bank-footer">
...
</div>
but it only appeared on one page.
I then found the footer-html mechanism in frappe.utils.pdf.prepare_header_footer() and changed the Print Format to:
<div id="footer-html" class="bank-footer">
...
</div>
This works correctly. The footer is now passed to wkhtmltopdf as --footer-html and appears on every page of a multi-page PDF.
I verified this with an actual generated PDF, not the browser print preview:
PAGES: 2
PAGE 1: Bankverbindung=True, IBAN=True
PAGE 2: Bankverbindung=True, IBAN=True
So the repeating footer itself is working correctly.
The remaining problem is the page number.
I would like the footer to display:
Seite 1/2
Seite 2/2
I found the standard Frappe template:
frappe/templates/print_formats/pdf_header_footer.html
which contains JavaScript similar to:
function subst() {
var vars = {};
var x = window.location.search.substring(1).split('&');
...
var x = ['frompage','topage','page','webpage','section','subsection','subsubsection'];
...
}
Therefore I tried:
Seite <span class="page"></span>/<span class="topage"></span>
However, the generated PDF contains empty values.
I checked the Frappe v16.35.0 source and found that frappe.utils.pdf.get_pdf() explicitly adds:
options.update({ "disable-javascript": "", "disable-local-file-access": "",})
before calling:
pdfkit.from_string( html, options=options or {}, verbose=True)
So the subst() JavaScript from the standard Frappe footer template cannot execute.
My questions are:
-
What is the recommended/supported way in Frappe v16.35.0 to display dynamic
Page X/Yinside afooter-htmlfooter while keeping JavaScript disabled? -
Can wkhtmltopdf’s native:
--footer-center "Seite [page]/[topage]"
be configured through Frappe’s pdf_options or another supported mechanism?
-
If
footer-htmlis already being used for a custom HTML bank footer, is there a supported way to combine the custom HTML footer with wkhtmltopdf’s native[page]/[topage]variables? -
Is there a Frappe hook or recommended customization point for this, without modifying Frappe core?
-
Is switching the Print Format to the Chrome PDF Generator the recommended solution for dynamic page numbers in Frappe v16?
I would prefer not to globally re-enable JavaScript for PDF generation, and I would also prefer not to modify Frappe core.
The important requirement is that the result must be the actual PDF generated by ERPNext, because this PDF will subsequently be uploaded to an external accounting system.
Thank you.