how to download pdf file from public folder in symfony

I’m using dompdf to generate invoices from html template, every work perfectly and the invoices are saved in the database with absolute filepath and filename, when I access to public/invoices I found all my pdf file there, I want to make a link button to download or open in the browser the file.

I create a link that take the absolute file like that :

{% for invoice in invoices %}
<tr>
  <td> {{ invoice.id }} </td>
  <td>{{ invoice.fileName }}</td>
  <td>{{ invoice.booking.user.name }}</td>
  <td>{{ invoice.booking.car.registrationNumber }}</td>
  <td>{{ invoice.booking.startDate | date('d-m-Y') }}</td>
  <td><a href="" class="btn btn-sm btn-outline-danger">Archiver</a></td>
  <td><a href="{{ asset('invoices/' ~ invoice.filePath) }}) }}" style="color: #DDDDDD" class="btn btn-sm btn-dark"><i style="padding-right: 10px" class="fa fa-download"></i>Télecharger</a>
  </td>
</tr>
{% endfor %}

I got this error :

No route found for "GET
/home/sahnoun/Downloads/SousseCar/public/invoices/aKRyaziz.pdf)%20%7D%7D"
(from "http://127.0.0.1:8000/admin/invoice/all")

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *