Help For "get_pdf" Utility Functions

I need a button that creates a pdf when pressed. I used the "get_pdf" function for this. But when I press the button I get this error.
“Cannot read properties of undefined (reading ‘responseText’)”


My JS Code;

frappe.ui.form.on('Offers', {
	refresh: function(frm) {
		frm.add_custom_button(__('Button'), function(){{
				method: "crm.scripts.generate_invoice", 
				callback: function(r) {
					// code snippet

        }, __("Tasks"));
        // buton finish


My python function:

def generate_invoice():
    test = "test pdf"

    html = '<h1>Invoice from Star Electronics e-Store!</h1>'

    # Add items to PDF HTML
    html += '<ol>'
    html += f'<li>{test}</li>'
    html += '</ol>'

    # Attaching PDF to response
    frappe.local.response.filename = 'invoice.pdf'
    frappe.local.response.filecontent = get_pdf(html)
    frappe.local.response.type = 'pdf'

Is there anyone who can help with this?

Do you see any error in server side…if you are running from bench? Hope you have the import
from frappe.utils.pdf import, get_pdf
you can try with the built in report_to_pdf in from your js

There is no error log about this issue on the server side and yes, I imported get_pdf.

you can try with the built in report_to_pdf in from your js

Can you write this a little more clearly?

Basically what I want to do is this; a button to save the document as pdf without using the embedded print button.

there is a frappe.render_pdf frappe/query_report.js at 30c866106327acbcb92e361bde96aaeed3b845de · frappe/frappe · GitHub
try using that in your generate_invoice function above. it does everything you are trying…
also try the PDF button in the actions menu of any report, if that works your code should work as well


Were you able to fix this?