4

I want to customize layout of PDF invoice by css and by adding product image on invoice in magento 2.

1

4 Answers 4

4

For customization or changing layout of pdf invoice we use zend framework's library functions and we need to override some files like:

  1. Magento\Sales\Model\Order\Pdf\Invoice
  2. Magento\Sales\Model\Order\Pdf\AbstratcPdf
  3. Magento\Sales\Model\Order\Pdf\Items\Invoice\DefaultInvoice
  4. etc.

In this files we can add custom variables, Change layout or add custom footer or table for Invoice PDF.

1

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:

--DomPDF
--mPDF

1

I hope this can help you. Here is enough explanation to fulfil your needs.

Magento 2: How to add footer in pdf invoice?

0

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

3
  • 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
    – Keyur Shah
    Mar 19, 2018 at 19:13
  • I've edited my content. Is that good now?
    – Stas Leo
    Mar 20, 2018 at 20:47
  • you can use pdf invoice for custom invoice with this module you can create custom template Jun 2, 2021 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.