Table of Contents
-
Introduction
-
Overview of Dolibarr's PDF Generation System
-
Default Document Models in Dolibarr
-
Locating and Understanding PDF Template Files
-
How PDF Generation Works in Dolibarr
-
Selecting a Default PDF Model
-
Adding Your Company Logo and Branding
-
Customizing Headers and Footers
-
Editing the Layout of PDF Elements
-
Customizing Font Styles, Sizes, and Colors
-
Modifying Table Structures for Products and Services
-
Showing or Hiding Specific Fields
-
Adding Custom Fields to PDF Templates
-
Localization and Language Considerations
-
PDF Templates and Module Integration
-
Creating a New PDF Model from Scratch
-
Best Practices for Upgrading Without Losing Custom PDFs
-
Testing and Debugging PDF Output
-
Performance Considerations in Large Documents
-
Conclusion
1. Introduction
Dolibarr’s PDF document generator is one of its most essential features. Whether you’re printing invoices, proposals, orders, or delivery notes, these documents often serve as official communication with clients, suppliers, and partners. This guide details how to customize Dolibarr’s PDF documents to reflect your branding, business logic, and layout preferences.
2. Overview of Dolibarr's PDF Generation System
Dolibarr uses PHP-based PDF templates to create documents. These templates are PHP files located in specific directories depending on the document type (e.g., invoices, orders). Dolibarr uses TCPDF, a widely used open-source PHP library, to render these PDFs.
Each module (like invoices or proposals) has its own PDF generation logic and template files.
3. Default Document Models in Dolibarr
Each type of document offers several standard models:
-
Invoices: crabe, azur, fraise
-
Proposals: elyse, azur
-
Orders: einstein, caracole
-
Shipments: rouget, expedition_lettre
These models can be selected from the configuration of each module and serve as starting points for customization.
4. Locating and Understanding PDF Template Files
Template files are stored in:
/htdocs/core/modules/<module>/doc/
For example, invoice templates are found in:
/htdocs/core/modules/facture/doc/
Each model corresponds to a .php
file, e.g., pdf_crabe.modules.php
. These files define layout, header/footer logic, and how data is rendered.
5. How PDF Generation Works in Dolibarr
When generating a PDF:
-
Dolibarr loads the selected template class
-
Retrieves business data (invoice, proposal, etc.)
-
Uses TCPDF to write content line-by-line
-
Saves the output to the
/documents/
folder
The entire process is triggered when clicking the Generate PDF button inside a document.
6. Selecting a Default PDF Model
-
Go to Setup > Modules > [Module Name]
-
Scroll to the PDF Templates section
-
Select the preferred model as the default
-
Optionally disable others to prevent users from switching
This sets the layout used for all generated documents of that type.
7. Adding Your Company Logo and Branding
Logos are managed from: Setup > Company/Organization
To add a custom logo:
-
Upload a logo image (JPEG or PNG preferred)
-
Ensure it's placed in
/logos/
-
Templates like
pdf_crabe
will automatically embed it
For more control, edit the write_file()
method in the template file to reposition or resize the logo.
8. Customizing Headers and Footers
Headers typically include:
-
Company name
-
Address
-
Document title
-
Reference number
Footers may contain:
-
Page numbers
-
Legal information
-
Terms and conditions
These can be customized in the template’s pdf->SetHeader()
and pdf->SetFooter()
logic or directly within write_file()
.
9. Editing the Layout of PDF Elements
You can adjust:
-
Margins and paddings
-
Font styles for titles, tables, and notes
-
Spacing between sections
-
Image placements
Use TCPDF methods like SetXY()
, MultiCell()
, and Line()
to position and format content.
10. Customizing Font Styles, Sizes, and Colors
Dolibarr uses TCPDF’s style engine. Examples:
$pdf->SetFont('dejavusans', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFillColor(230, 230, 230);
You can switch fonts (DejaVu, Courier, Helvetica) and apply bold/italic/underline as needed.
11. Modifying Table Structures for Products and Services
The main product table includes:
-
Description
-
Quantity
-
Unit price
-
Total
You can:
-
Change column order
-
Add/remove columns (e.g., SKU, supplier info)
-
Format currency display
Locate the loop that processes $object->lines[]
in the template file and adjust accordingly.
12. Showing or Hiding Specific Fields
To hide/display fields:
-
Use configuration constants (set via Setup > Other Setup)
-
Add conditional logic in PHP, e.g.:
if (!empty($line->ref)) {
$pdf->MultiCell(...);
}
You can also check user permissions or document types to conditionally render content.
13. Adding Custom Fields to PDF Templates
If you’ve added extra fields:
-
Ensure they’re enabled and filled in the UI
-
Access them via
$object->array_options['options_fieldname']
-
Format and insert using
MultiCell()
or other TCPDF functions
Custom fields work for third parties, products, and most document lines.
14. Localization and Language Considerations
PDFs respect Dolibarr’s language settings. If generating multilingual documents:
-
Set language in
$outputlangs
before writing content -
Use
load_langs('bills')
or similar
Ensure UTF-8 encoding and fonts that support special characters.
15. PDF Templates and Module Integration
Some modules like Contracts or Projects have their own templates. If integrating data from other modules:
-
Extend the template logic to query extra fields
-
Use hooks or override core templates if necessary
Always keep cross-module dependencies documented.
16. Creating a New PDF Model from Scratch
-
Copy an existing model (e.g.,
pdf_crabe.modules.php
) -
Rename the file and class (e.g.,
pdf_mycustom.modules.php
andpdf_mycustom
) -
Register it by refreshing the module settings page
-
Test and iterate
Keep your custom templates outside /core/
if possible to avoid overwrites during upgrades.
17. Best Practices for Upgrading Without Losing Custom PDFs
-
Never modify built-in templates directly
-
Store custom files in a
/custom/
or backup directory -
Use version control (Git) to track changes
-
Test after each Dolibarr upgrade
Also, document your customizations for team awareness.
18. Testing and Debugging PDF Output
To debug:
-
Use
print_r()
orvar_dump()
(log to file, not screen) -
Check
$object
structure -
Review TCPDF output for layout errors
Use sandbox invoices for safe testing.
19. Performance Considerations in Large Documents
For invoices with many lines:
-
Minimize image and font usage
-
Paginate properly
-
Avoid unnecessary loops
-
Use
SetAutoPageBreak(true)
to prevent cut-off content
Performance tuning helps avoid timeouts or memory errors.
20. Conclusion
Customizing Dolibarr's PDF documents allows businesses to produce professional, on-brand, and functional output. From minor layout tweaks to building entirely new templates, understanding how the PDF system works will give you full control over document generation.