4 alternative invoice pdf templates

Sending my thanks to all the Dolibarr developers I want to share 4 alternative invoice pdf templates.

As this forum won’t let me upload php files or archives, I share the github URL of my pull request where you can find the 4 templates and can copy them to your server, (click on the grey link 'github.com/Dolibarr/dolibarr.’ from below, not on the blue link):

Apart from some visual improvements, I reordered the columns, setting them in the most commonly used order: Product Description, Quantity, Unit Price, Taxes, Total Excluding Taxes.

4 Likes

Two of the templates also include an additional column: taxes amount per line, which is expected in some countries:

Two of the templates, the ones ending in ‘wt’ (which stands for ‘without table’), have a more modern look, as they only include the horizontal lines, which are enough to display a clear list of products and prices. This design is also adopted by many other well-known ERP applications:

All the templates also contain the following commented lines:

// Add background image
//$pdf->Image(DOL_DOCUMENT_ROOT.'/core/modules/facture/doc/background1.png', 26, 90, 160, 110);
//$pdf->Image(DOL_DOCUMENT_ROOT.'/core/modules/facture/doc/background2.png', 56, 100, 100, 100);

If you uncomment one of the lines, you can add an image as background for the table of prices, as can be seen in the examples below. This can be useful if someone wants to include a highly transparent version of their logo or of a pattern, as background for the invoice, in order to personalize it. (The two png images are free for commercial use without attribution, as they are taken from pixabay.com).

The two sample backgrounds:

The column headers: ‘Quantity’, ‘Unit Price’, ‘Taxes’, ‘Taxes Amount’, ‘Total Excl. Tax’ are handwritten in the pdf template, so, if someone needs them in French/German, etc. the easiest way is to replace them with their French/German translation, directly in the pdf templates.

To use all the templates you have to place them in ‘dolibarr_root_directory/core/modules/facture/doc’. Then don’t forget to go to Home > Setup > Modules/Applications > Invoices > click on the Setup wheel, then activate all the 4 pdf templates using the switch in the Status column, under ‘Invoice documents models’.

I couldn’t list all the images in one post. Since I’m a new user, the forum won’t let me.

3 Likes

Thanks so much for this :slight_smile:

Hi,

Thanks for that !
Can you put htem here in .zip ?

No, this forum won’t let me post any type of archive here. I posted them as a zip archive at the bottom of the pull request thread. You can download the zip from there:


Replace the background images with any image that you like after you make it highly transparent (about 10% opacity). Both the pdf templates and the background images have to be placed in the ‘dolibarr_root_directory/core/modules/facture/doc’ directory, then you have to enable each template in ‘Home > Setup > Modules/Applications > Invoices > Setup’. Afterwards, you can just select the templates on the invoice card, instead of selecting the default ‘crabe’ template, when generating the pdf invoice.

3 Likes

Hi,

Normally zip are allowed in the forum.

pdf_templates.zip (765.8 KB)

No, new users like me are not allowed to upload zip archives or other types of archives.
I’ve just tried again to upload a zip archive and I received:
‘Sorry, new users can not upload attachments.’

Hi,

Yes sorry, when you are below 10 messages…
I have updated your profil, you should be able now

1 Like

This really Helps. thank you

How to change the order of these column headers to lets say: Description, Unit Price, Quantity, VAT, Total?

The instructions from below have been tested with Dolibarr 12.0.3 and they probably work for older Dolibarr versions too. They haven’t been tested with the latest version of Dolibarr, since I haven’t installed it yet.

If you want to change the order of columns, so as to have: Description, Unit Price, Quantity, Taxes, Total Excl. Tax, first copy the file pdf_anaxagoras.modules.php from the pdf_templaces.zip archive mentioned above, to the core/modules/facture/doc directory of your Dolibarr installation. Then, to be able to see the ‘anaxagoras’ template in the ‘Doc template’ drop-down list on an invoice and select it to generate the invoice based on that template, first go to Home > Setup > Modules/Applications > List view, then under ‘Financial Modules’, click the Setup wheel on the Invoices row. Then, under ‘Invoice documents models’ you will find the new pdf invoice template, ‘anaxagoras’. Enable it by turning on the Status switch. Next, go to Billing > Customer Invoices > List, and click on an invoice that you want to generate. If you scroll down to the ‘Doc template’ drop-down list, you will see the new ‘anaxagoras’ template in the list and you will be able to select it to generate the pdf invoice.

Now, to place the Unit Price column before the Quantity column, open the core/modules/facture/doc/pdf_anaxagoras.modules.php file and make the following changes:

Search for the following lines:

$this->posxqty=58;
$this->posxup=85;

replace them with the following lines:

$this->posxup=53;
$this->posxqty=94;

Then replace the following lines:

$this->posxqty=93;
$this->posxup=109;

with these lines:

$this->posxup=88;
$this->posxqty=118;

Next, search for this line:

pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxqty - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);

and replace it with this:

pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxup - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);

Then, search for this:

pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxqty - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);

and replace it with this:

pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxup - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);

Next, search for this:

$pdf->MultiCell($this->posxup - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars

and replace it with this:

$pdf->MultiCell($this->posxtva - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars

Then search for:

$pdf->MultiCell($this->posxtva - $this->posxup - 1, 3, $up_excl_tax, 0, 'R', 0);

and replace it with:

$pdf->MultiCell($this->posxqty - $this->posxup - 1, 3, $up_excl_tax, 0, 'R', 0);

Next, search for:

$pdf->MultiCell($this->posxup-$this->posxqty, 2, $outputlangs->transnoentities("Quantity"), '', 'C');

and replace it with:

$pdf->MultiCell($this->posxtva-$this->posxqty, 2, $outputlangs->transnoentities("Quantity"), '', 'C');

and finally, search for:

$pdf->MultiCell($this->posxtva-$this->posxup-0.5, 2, $outputlangs->transnoentities("Unit Price"), '', 'C');

and replace it with:

$pdf->MultiCell($this->posxqty-$this->posxup-0.5, 2, $outputlangs->transnoentities("Unit Price"), '', 'C');

The end result will look like this:

If you want to change the text of the column headers, just search for them and replace them manually. For example, to change ‘Taxes’ to ‘VAT’, search for this line:

$pdf->MultiCell($this->posxdiscount-$this->posxtva+4.5, 2, $outputlangs->transnoentities("Taxes"), '', 'C');

and change it to this:

$pdf->MultiCell($this->posxdiscount-$this->posxtva+4.5, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1 Like

Thanks for the solution, it works :slight_smile:

So will there be any new templates in the future? In my opinion even 1 neat looking one would be sufficient (even if it’s just an invoice template). I saw that eldy closed the github issue as too much time/too much stuff has changed over the time. Yes 4 templates might be overkill but 1 more would maybe work?

I can’t quite grasp the extra fields, etc explained in the github issue. I think another template where you don’t have to change anything would be awesome.

atm-john wrote on the above mentioned github discussion regarding the changes made to pdf templates:

from 12.0 of Dolibarr version some new Models were introduced, they have possibility to allow custom column organisation from hooks, for exemple, find defineColumnField in pdf_sponge.
The first step was here
For the second step we introduced extrafields in columns and description of PDF
Now the next step is to create an user interface to manage cols for all compatible PDF models

So, it seems that some hooks and new fields have been introduced into the pdf templates of Dolibarr versions newer than 12. It seems that these changes allow reordering columns and adding new columns on invoices. The plan might be to create a user interface that would allow the admin to easily change column order or to add custom columns without editing the pdf templates. I’m still using Dolibarr 12, so I haven’t tested the new features. I highly suspect that the 4 pdf templates that I created and posted on this thread will work in Dolibarr 13, 14 and 15 if you place them in dolibarr_root_directory/core/modules/facture/doc, then enable them by going to Home > Setup > Modules/Applications > Invoices > clicking on the Setup wheel, then activating all the 4 pdf templates using the switch in the Status column.

1 Like

Hi, i want to remove taxes, and unit prices without taxes, just Quantity, price with VAT, and total price?