Automatically Generate and Download PDF Reports with Custom Print Formats

Hey everyone,

I have a script report with a custom print format in my Frappe application. Currently, I can manually generate the report and download it as a PDF by applying filters and clicking the download button.

However, I’m looking for a way to automate this process. Is it possible to generate the report and download the PDF or print it automatically based on a given array of filter options? For example, if I provide an array of filter options, I want the system to apply each filter one by one, generate the report, and download the PDF or print without requiring manual intervention.

Has anyone implemented a similar workflow or know of any methods to achieve this automation within Frappe? Any suggestions or insights would be greatly appreciated.

Thank you!

I found an answer.
Step 1: I wrote the Jinja HTML template to create the custom print format according to my requirements.
Step 2: I developed a Python class to handle the filter options, iterate through them, render the Jinja template with the appropriate context, and convert it to HTML
Step 3: Utilizing Frappe’s frappe.utils.get_pdf method, I passed the HTML content to generate the PDF. This approach allowed me to automate the process of generating the report and downloading the PDF seamlessly

refer to this image for my class structure

1 Like