Help For "get_pdf" Utility Functions

Hello.
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’)”

ss

My JS Code;

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

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


	},
	validate(frm){
		location.reload();
	}
});

My python function:

@frappe.whitelist(allow_guest=True)
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 print_format.py 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 print_format.py 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

frappe.render_pdf(html,{})

Were you able to fix this?