'Return name of file after converting from html to pdf using pdfkit

I have converted some html to pdf successfully. I need to return the name of the pdf file so that I can attach it and send it via email. Function that converts to pdf.

def generate_pdf_statement(
     entries: list,start_date: str, end_date: str, patient_id: int
):
   
    auth = authenticate()   
    patient_details = get_patient_details(auth["key"], patient_id) 

    # html_content = get_template(f"statements/{cust_type}_statements.html").render(
    html_content = get_template("email/patient_statements.html").render(    
        {
            "start_date": start_date,
            "end_date": end_date,
            "patient_email": patient_details.get("patient_address")
            and patient_details.get("patient_address")[0]
            and patient_details.get("patient_address")[0].get("email"),
            "patient_phone": patient_details.get("patient_address")
            and patient_details.get("patient_address")[0]
            and f"+{patient_details.get('patient_address')[0].get('callingcode')}{patient_details.get('patient_address')[0].get('phone')}",
            "patient_name": patient_details.get("name"),
            "entries": entries,
        }
    )
    file = pdfkit.from_string(html_content,"out.pdf")
    
    return file

This is where I send my email:

pdf_report = generate_pdf_statement(statement_entries,start_date,end_date,patient_id)
            
            firstname = user and user.first_name or ""
            message = render_to_string(REPORT_DOWNLOAD_TEMPLATE, {"name": firstname})

            email_send(
                subject="Patient statements Download Success",
                body=message,
                _from=settings.EMAIL_HOST_USER,
                _to=email,
                _file_attachment=pdf_report
            )

            logger.info("Patient statements sent successfully to user")

However, the value of file returned is a boolean true. And if I do this by not specifying the name I get bytes returned

pdfkit.from_string(html_content,"out.pdf")

I need to save the name and return the file name so I can attach



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source