I want to customize layout of PDF
invoice by css
and by adding product image
on invoice in magento 2.
4 Answers
For customization or changing layout of pdf invoice we use zend framework's library functions and we need to override some files like:
- Magento\Sales\Model\Order\Pdf\Invoice
- Magento\Sales\Model\Order\Pdf\AbstratcPdf
- Magento\Sales\Model\Order\Pdf\Items\Invoice\DefaultInvoice
- etc.
In this files we can add custom variables, Change layout or add custom footer or table for Invoice PDF.
As far as I know, CSS is only used for styling HTML and XHTML. So, in your case, we should use some PDF libraries for generating PDF files from HTML:
I hope this can help you. Here is enough explanation to fulfil your needs.
You can try "PDF CUSTOMIZER" M2 extension from PotatoCommerce. This extension converts HTML and CSS to PDF documents automatically. In fact, it replaces native Magento templates with custom templates, which can be edited just as normal HTML page. PDF Customizer uses wkhtmltopdf library. For example, product image can be added to PDF this way:
<img src="{{var item|small_image}}" width="100" height="100">
You can see all available variables on this page: PDF Customizer
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Commented Mar 19, 2018 at 19:13
-
-
you can use pdf invoice for custom invoice with this module you can create custom template Commented Jun 2, 2021 at 8:08