This feedback section focuses on pdf generation on the www.forum-foceen.fr site. This article was written jointly with Julien Enselme, the main player on this feature.
The generation of invoices, order forms, other documents sent by email or available for download is a frequent need, if not indispensable for e-commerce sites.
Let's leave aside the emailing side, and focus on pdf generation.
There are a multitude of modules for generating invoices:
Each with a more or less different approach, leaving more or less freedom for customisation. I have to admit that having such a diversity of modules is both good for the variety of approaches, but for getting tangled up, it's also pretty good.
The chosen solution doesn't go through any of these modules!
Almost finally, Commerce PDF Invoice relies on the Views PDF module, which allows you to generate PDFs from Views so as far as freedom of customisation is concerned, it's very well positioned. Except that, to sum up, Commerce PDF Invoice simply adds 2 views configured for invoice generation, so you might as well use Commerce PDF Invoice to see how to configure your own views and thus avoid having an additional module to manage in production.
Implementation
With version 1.0 of Views PDF, the interface was quite poorly designed, it was easy to miss options such as font size (whose default value was not taken into account which to my surprise generated blank pdf's and required a lot of debugging time). Version 1.1 of the module has greatly improved this interface, which is much more convenient to use and fixes the problem with default fonts.
Principle
- Make a template in PDF format that will serve as the background on which the dynamic information will be added by Views. Typically on this template will be put the site/company logo, information common to all invoices, etc.
- once this template has been created, ask the view to use it (it can be used by several views),
- use Views as usual, except that it will be displayed on a PDF,
- displaying information on the page can be done :
- relatively in relation to many choices, in relation to the page, in relation to another field, etc.
- absolutely by specifying height and width, which is quite long and tedious to do, but if an element needs to be displayed in a specific place, it meets the need well.
One particularity, as this is an invoice/order form, the order elements are displayed in a different way, so you have to play with the inclusion of other views (module included in the Views PDF project), in the final view and ensure that the views included use the same template.
The difficulty with this functionality comes from the fact that the Views PDF interface is quite complex to get to grips with (less so since it was improved) and the fact that the module still has a few imperfections, such as duplicating the values of included views, and you have to play with the display and options to ignore the problem.
Conclusion
Views PDF is a complex module to get to grips with, requiring a few libraries, but extremely powerful because it is not limited to pdf generation in an e-commerce context.
See part 1 of this feedback.