How to get pdf attached to sales invoice in print format

Hi Team,

I am using jinja code and wrote custom print format for sales invoice.At the end of print format i want to show attached files in sales invoice.

I tried but in preview it will show but when i click on PDF nothing is showing.

{% set pdf_data = frappe.get_list("File", filters={"attached_to_name": doc.name}, fields=["*"]) %} {% if pdf_data %} {% set file_url = pdf_data[0]['file_url'] %} {% else %}

No PDF found.

{% endif %}

Please help me

Thanks,
Jyoti

Try it.

{% set attachments = frappe.get_all("File", filters={"attached_to_name": doc.name, "attached_to_doctype": "Sales Invoice"}, fields=["file_url", "is_private"]) %}
{% if attachments %}
    <div>
        <h3>Attachments:</h3>
        {% for file in attachments %}
            {% if not file.is_private %}
                {{ frappe.utils.get_url(file.file_url) }}
            {% endif %}
        {% endfor %}
    </div>
{% else %}
    <p>No attachments found.</p>
{% endif %}

Thanks for your reply.But again when i click on PDF it is showing like this

try it.

<a href="{{ frappe.utils.get_url(file.file_url) }}" target="_blank">{{ file.file_name }}</a>

This code shows the Attached Fils I guess. But what if you want to actually display the PDF as part of the Print Format?

Like let’s say the Invoice is for T&M and as part of the invoice, time and expenses are being billed. Let’s say the timesheet and the Expenses Statements/Bills are all attached to the Invoice as a PDF. Now you want the PDF generated from ERPNext for the Sales Invoice in the first part and then show the supporting documents to the invoice.

Thanks

Jay

Hi, you can use the Embed HTML Tag to display PDF files in your print format.

Edit: I assume this will work for print, but it will render a white page if you try to export as PDF as wkhtmltopdf might not fully support embed. I may be wrong, but in that case you need to switch your PDF rendering engine to Chrome Headless.

{% set attachments = frappe.get_all("File", filters={"attached_to_name": doc.name, "attached_to_doctype": "Sales Invoice"}, fields=["file_url", "is_private"]) %}

{% if attachments %}


Attachments:


{% for file in attachments %}
{% if not file.is_private %}

{% endif %}
{% endfor %}

{% else %}

No attachments found.


{% endif %}

tried like this but again same problem when i click on odf empty page showing.