Introduction

Recently, I had to make amendments to the Dolibarr CRM Invoice design and text. At first glance, it seemed too hard to manage. However, after some research, I found that there are two primary ways to change an invoice:

  • Option 1: Changing the ODT file.
  • Option 2: Changing the PHP code directly.

Being a PHP professional, I chose the PHP way. I have learned a lot of things that can be modified easily, so I thought I would share this guide for others willing to change the Dolibarr invoice.

Getting Started: The File You Need

All you need to do is make changes in one specific PHP file. Navigate to the following path on your server:

/public_html/db/core/modules/facture/doc/pdf_crabe.modules.php

How to Change Date Format

One of the first changes I made was changing the Date format of the Invoice from MM/DD/YYYY to DD/MM/YYYY.

To do so, I defined my own function:

function _changeDateFormat($str) { $str = explode("/", $str); $str2 = $str[1]."/".$str[0]."/".$str[2]; return $str2; }

Then, I replaced the original output line and added my defined function to wrap the date output:

$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateInvoice")." : " . $this->_changeDateFormat(dol_print_date($object->date,"day",false,$outputlangs)), '', 'R');

How to Change Specific Text

Anything written between $outputlangs->transnoentities is the output that is going to print. You can identify the correct text string and replace it directly in the code.

How to Insert New Text

You can use the MultiCell method to insert any custom text you need.

$pdf->MultiCell($widthrecbox, 5, "Your Text Here", 0, 'L');

Formatting, Styling & Layout

Setting Font Size

To change the font size of text in the invoice, use the SetFont method. You can subtract or add to the default size variable.

$pdf->SetFont('', '', $default_font_size - 1);

Drawing a Rectangle

You can draw a rectangle using the following parameters:

$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);

The parameters represent: X Coordinates, Y Coordinates, Width, and Height.

Setting Position (X, Y)

To move the cursor to a specific position before writing text:

$pdf->SetXY($posx+2, $posy-5);

Filling Color

To fill a particular area with color (values are in RGB format):

$pdf->SetFillColor(224, 224, 224);

Setting Text Color

To change the text color (values are in RGB format):

$pdf->SetTextColor(0, 0, 60);
Ucodice Team

The Ucodice Team is a group of passionate developers, designers, and strategists dedicated to delivering top-tier IT solutions to clients worldwide.