An easy way to modify pdf templates

Hi to all.
I’m new to dolibarr, but takin a look at the forum, i’ve noticed that many users (who are not programmers as me) have so many problems to modify the templates (invoices for examples) for their needings.
It would be usefull for all that people that would like to use dolibarr, but aren’t programmers (think about all that small-size enterprises), to have an interface that let you modify your template without knowing the fpdf code.
I think that this will accelerate the spreading of Dolibarr, cause i think it’s really a good product.

I also suggested this feature, and currently there are already two candidates technologies:

* PDML www.pdml-pdf.net/
* html2pdf html2pdf.fr/

The main advantage of these two technologies are that they completely interface over the FPDF library, which is the one currently used by Dolibarr.

However, you would have to adapt the Dolibarr PDF generator and add a few special constructs, to allow for tags and the generation of lines of products/services.

This is a project I’d like to do, and make it available either as opensource if enough persons are able to donate to this project, or otherwise commercial if the donation system does not appeal so much.

Another two alternative solutions:

* PrinceXML (http://princexml.com/) which can convert HTML with CSS styling directly into PDF, and is currently the best available library to do this kind of job. However, it is a commercial product.
* Directly use the WriteHTML() and WriteHTMLCell() methods of FPDF (natively available) to make your template from HTML instead of making it from php code. However, the HTML support is quite limited, so it would be a bit difficult to make complex designs using this method.
Here is a good example of code for doing this method:
http://indianicorange.wordpress.com/2011/05/07/how-to-generate-html-to-pdf-using-tcpdf/

We have used http://code.google.com/p/wkhtmltopdf/ with some success in another php application. Also used http://www.tinybutstrong.com/ as the templete engine for mergign data.

I would like to modify the invoices rather than have to buy the Point of Sale for my service business.
With the point of sale is the receipt smaller?
Does it work with a small receipt printer with say 3" paper rolls? That would be great!!!
Paper, ink and electric add up.
To print one full page it costs me about $ 0.07 seven cents on the deskjet.
HP keeps increasing the price of ink cartridges.

Open Office can creates PDF files…

I will like to vote for this also.

The way dolibarr creates pdf is brilliant, but it will be powerfull if everybody could create their own model.

I also understand that it is becoming more necessary for users to make a donation to support this and other suggestions … :blush:

This would be a great help for every non-developer.
+1 to the vote list

Hi,

This is a alternative to custom pdf templates.

www.dolibarr.org/t/pdf-custom-invoice/8894/1

Regards,
Marcelo

In fact guys, I think I have found a good way to finally do this: an easily editable WYSIWYG editor to make PDF documents.

I will try to develop a quick proof-of-concept in June (I won’t develop all the functionalities, but I will give the opensourced sourcecode, so that Dolibarr devs can develop it further if they want to).

I’ll keep you updated when how this works out.

I have been struggling with this problem for a while both in dolibarr and Joomla. Would be interested in your idea, can you outline your thoughts. Anything I can do to help speed things along?

@toomanylogins: thank you for your offer, but no, i only need to have a bit of spare time to make a first version.

When the code will be released, you will be able to contribute to the code with features you want (because I won’t add extended features such as templates import, templates management, and such stuff, only the basic implementation of saving one template with substitution of variables, which should be enough for most people for a first release).

+1 for easy PDF layout editing.

I hope in the very near future there will be a WYSIWYG editor to make your own Invoice Layout.

I now use ODT and it is working fine, but in combination with the ‘dunning’ plugin it is not working.
So I really would like to switch to PDF, but need 12 different layouts and it is just not easy (for me not even doable) to do so with the current programming of the PDF invoice.

If somebody would know how to use ‘dunning’ with ODT or has another idea how to solve this PLEASE let me know.

Edwin

Sorry guys, I decided to drop this project. After discussing with a few people about it, it seems this solution won’t fit for all, thus it is not worth the time it will cost to develop it.

However, here is the general outline of the idea if someone wants to develop it:

USER INTERFACE

1- make a template manager, storing HTML templates, and using CKeditor as the frontend. This interface should offer an example template, and should be able to store new templates saved by the user. Variables substitution should work just like with ODT, but with HTML tags to format your page in addition.

2- when you want to generate your document, you should be able to see the template in the templates drop-down list (on the module’s page, along other templates), with two choices for each one: one for ODT, and one for PDF generation.
Eg: your template is called “mylittletemplate”, you should see in the list “mylittletemplate.odt” and “mylittletemplate.pdf”

3- Generate and you get your document in the file format you want. Thus you just need to make one template, and you can generate in any format you want later.

DEV PART

To make this system work, the basic idea is that we start from an HTML template, which will then be processed into a templating system to substitute variables and expand products’ lines, then finally we can convert the resulting HTML code to pretty much any format we want (there are many converters HTML -> whatever, while there’s no ODT -> PDF nor PDF -> ODT).

To detail the whole process:

1- Make the HTML templates manager, using CKeditor as the interface. Simply store each template in the database as a “text()” sql datatype.

2- Make the HTML templates be shown inside the dropdown list of templates on modules’ pages.

3- At document generation:

A. Preprocess the template: using the user defined HTML template, we use TinyButStrong as a templating system to substitute variables and to expand products’ lines, similarly to what does the library odtPHP. In addition, using TinyButStrong will offer more freedom to users to make their own expandable data collections (we can imagine that we in fact expand any data array related to a Dolibarr object, not just products’ lines, but also contacts, etc.).

This is actually the trickiest part, but also the most rewarding one.

B. Convert to a file format: now that the final HTML output is formatted, we can just convert it to any file format, for example using OpenTBS to convert to ODT (or even .DOC !). To convert to PDF, there are plenty of HTML to PDF libraries, like HTML2PDF and here’s another one.

ADVANTAGE

The main advantage of this framework is of course that with only one template, you would be able to generate pretty much any kind of file format. Also, it would be quite easy to add the support for the generation of a new file format, it would only be a matter of plugging in an HTML->your format converter.

Another advantage would be that we would have a very powerful templating system, allowing to do all kind of fancy dynamic templates.

Lastly, the management of variables substitution would be unified, and probably the template generator could be too, instead of having one PDF + one ODT generator for each module. The only thing that would change here would be the variables substituted, but with a clever design, it would only be a matter of variables in the HTML templates, no change in the php code.

SHORTCOMINGS

The main limitation people told me about this framework would be that, indeed, using CKeditor you would lose the ability to view your template per page (you would only see an undefinitely long HTML page, no Word-like page view).

However, you can set page breaks in CKeditor.

Ah and here’s also an interesting tool, which converts ODT into HTML: Ophir.php

+1 for easy PDF layout editing.

I think it’s time to resume this topic!!!
anyone has news?

I have started a module that converts pdf to odt but poor guy only runs on windows.

Sorry odt to pdf.

@ndrosis: Of course there are ways to convert ODT to PDF and vice versa, but they require external applications and thus to execute binaries like Pandoc, which is not available on shared webhosts. And this also doesn’t solve the problem of heterogenous document generation (ie: a different generator for PDF and for ODT).

Just to add that there are some new libraries to convert HTML -> PDF and which seems to do a great job from the comments I have read:
- http://www.mpdf1.com/mpdf/index.php
- https://github.com/Simanas/ReportMesh

And here’s a tutorial:

Thanks

@lrq3000,

I wanted to ask can you give me a clue on how to convert list of products to pdf so i can print. I want to be able to print out list of products as a catalog.

Any idea.

Look this module, I think is exactly what you need

https://www.dolistore.com/en/modules/478-2Catalog-STS.html