print_designer
print_designer copied to clipboard
Load Fonts Locally instead of Google Fonts to improve performance.
I'm loving the new print designer, thanks so much for your work on it! That said, I am having a bit of an issue with the performance of the system. When non-print-designer print formats are used, the rendering feels instantaneous, but there's a noticeable lag on Print Designer formats, up to 7 seconds before the document is rendered. This is an obvious annoyance. How can I help diagnose the root cause?
@batonac reason behind this is fonts are loaded from google that is adding lag. i am trying to figure out a way to load from local if possible that will make it instantaneous like normal formats.
That's possibly a contributing factor, but I just narrowed this down in the Chrome DevTools Network monitor.
When trying to load the print format in the print preview windows (i.e. /app/print/Sales%20Invoice/ACC-SINV-2023-00022
, etc) the request associated with the lag is to /api/method/frappe.utils.print_format.download_pdf
. That specific request is taking 6+ seconds, and blocking the rest of the rendering until it's finished.
That seems like a bug, since the print preview is rendering in HTML, and a PDF isn't needed until a user additionally requests it, correct?
@batonac print designer doesn't provide html view.
PDF is generated ( fonts are loaded ) on the server and downloaded in print view then pdfjs is used to draw that pdf in print view.
However, this won't be noticeable as much in production server due to them having high bandwidth. if you have any production server you can confirm that issue is in fact fonts by trying on it. It will be much faster.
Thanks for drawing my attention to this. I am also very annoyed by this delay, will try to fix this.
Ah, that makes sense! I suppose an alternative would be to generate an HTML preview directly, but I can sympathize with the chosen solution.
@batonac This is done to make sure there are no discrepancy in print format.
in China access to google is blocked, so print designer is almost not usable due to this google font issue.
@szufisher I am aware of this but for some reason wkhtmltopdf breaks with local fonts so using google fonts for now. will try to figure out solution
What's the possibility that WeasyPrint could be used as the renderer instead of wkhtmltopdf?
A basic implementation already exists at frappe/frappe/utils/weasyprint.py