Environment
- ERPNext: v15.107.0
- Frappe: v15.107.2
- India Compliance: v15.28.0
- Browser: Chrome
- OS: Ubuntu 24.04
Issue
When clicking the Print button on a Delivery Note, the browser print dialog shows 2 pages (second page is blank). However, opening the same printview URL manually shows 1 page correctly.
Steps to Reproduce
- Open any Delivery Note
- Click Print button → browser print dialog opens → shows 2 pages
- Open the same URL directly without
trigger_print=1→ press Ctrl+P → shows 1 page
URLs Comparison
2 pages (Print button):
/printview?doctype=Delivery Note&name=DN-XXXX&trigger_print=1&format=Delivery Note v2&no_letterhead=1
1 page (direct URL):
/printview?doctype=Delivery Note&name=DN-XXXX&format=Delivery Note v2&no_letterhead=1
Key Finding
Both URLs generate identical HTML source. The only difference is trigger_print=1 which causes window.print() to fire automatically on page load.
This suggests window.print() is firing before the browser has fully rendered the page layout, causing it to calculate incorrect page height and produce a blank second page.
Suspected Root Cause
In frappe/templates/print_formats/standard.html:
window.print();
This fires immediately without waiting for full page render. A setTimeout delay may fix it but we have not tested this as it would be overwritten on updates.
Expected Behavior
Print button should show 1 page same as opening the URL directly.
Workaround
Users must open the printview URL directly (without trigger_print=1) and press Ctrl+P manually.