Error in PDF Generation on ERPNext 15 with WeasyPrint: TypeError in pydyf.PDF()

I am encountering an issue with PDF generation in ERPNext 15 hosted on a DigitalOcean server running Ubuntu 24.

When trying to generate a PDF, In a Print Format generated with WeasyPrint, I receive the following error:

TypeError: PDF.__init__() takes 1 positional argument but 3 were given

This error occurs in the pydyf.PDF() function, which is being called by WeasyPrint. I am currently using the following versions:

  • WeasyPrint: 59.0
  • pydyf: 0.10.0
  • erpnext: 15.30.0
  • frappe: 15.35.0

Many Git Discussions are leading me to this link, but I don’t understand what It is trying to say: https://github.com/Kozea/WeasyPrint/issues/2200

I also attempted upgrading WeasyPrint, but encountered the following dependency conflict:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.

frappe 15.35.0 requires WeasyPrint==59.0, but you have weasyprint 61.0 which is incompatible.

I’d appreciate any insights or suggestions from the community regarding this error and potential compatibility issues between WeasyPrint and pydyf.

If I have missed to mention anything and more details are needed, please let me know.

Downgrading the pydyf to version to 0.6.0 solved the issue.

I had to do bench restart for the changes to take effect.