Changes

Line 15: Line 15:  
An ODT template does not require PHP knowledge. To build an ODT template, see this page [[Create an ODT document template]].  
 
An ODT template does not require PHP knowledge. To build an ODT template, see this page [[Create an ODT document template]].  
   −
=Prerequisite=
+
=Prerequisites=
    
*Dolibarr: 3.0+
 
*Dolibarr: 3.0+
Line 29: Line 29:  
propale for commercial proposals
 
propale for commercial proposals
 
facture for invoices
 
facture for invoices
commandes for orders, etc...  
+
commande for orders, etc...  
 
and finally '''doc''' or '''pdf'''.
 
and finally '''doc''' or '''pdf'''.
For instance, a customized proposal template will be located in '''...core/modules/propale/doc/'''
+
For instance, proposal templates will be located in '''...core/modules/propale/doc/'''
   −
=Create your new template=
+
The list of recommended PDF Models :
Do not modify a template. Copy the file and rename it.
+
{| class="wikitable"
For this example, we will call the new template 'mycompanyblue', based on the template 'azur':
+
!Module
 +
!PDF Model name
 +
!Dolibarr min version
 +
|-
 +
|Shipping
 +
|espadon
 +
|V12
 +
|-
 +
|Order
 +
|eratosthene
 +
|V12
 +
|-
 +
|Invoice
 +
|sponge
 +
|V12
 +
|-
 +
|Proposal/Quotation
 +
|cyan
 +
|V12
 +
|-
 +
|Supplier order
 +
|cornas
 +
|V12
 +
|-
 +
|Delivery
 +
|storm
 +
|V13
 +
|}
   −
*Copy and paste file pdf_propale_azur.modules.php
+
=Create a new template=
*Rename the copy as pdf_propale_mycompanyblue.modules.php
+
==For an existing core module==
*Edit and make the following changes in the code:
+
Do not directly modify an existing template.  
   −
#Rename 'Class pdf_propale_azur { ' to 'Class pdf_propale_mycompanyblue { '
+
Although it is possible to copy the file of the template used as example into a new name in same directory and edit it to change content it is strongly recommended not to modify any core file or structure(If you want to fix something use the project Github page to propose your changes).
#Rename 'Function pdf_propale_azur ($db=0)' to 'Function pdf_propale_mycompanyblue ($db=0)' . This may not exist.
  −
#Rename constant $this->name to match your new template name.
     −
For example for 'azur' template, change line '$this->name = "azur";' to '$this->name = "mycompanyblue";'.
+
Instead use the [[https://wiki.dolibarr.org/index.php?title=Module_development#Module_creation_with_the_module_builder |Module Builder]] available from v12.0 to create your own module even for just a new template.
   −
#Save file. Now the template will be available in the list of models in Dolibarr.
+
For this example, we will call our new module 'mymodule' and our template 'mycompanyblue', based on the existing template 'cyan':
#Test this model (see previous section) before going further ...
      +
 +
*Copy and paste file pdf_cyan.modules.php into custom/mymodule/core/modules/propale/doc
 +
*Rename the copy as pdf_mycompanyblue.modules.php
 +
*Edit the file and make the following changes in the code:
 +
 +
#'class pdf_cyan extends ModelePDFPropales' to 'class pdf_mycompanyblue extends ModelePDFPropales'
 +
#'$this->name = "cyan";' to '$this->name = "mycompanyblue";'.
 +
#'$this->description = $langs->trans('DocModelCyanDescription');' to '$this->description = $langs->trans('DocModelMycompanyblueDescription');'.
 +
#Save file.
 +
 +
*Edit the file custom/mymodule/core/modules/modMymodule.class.php and make the following changes in the code:
 +
 +
#'models' => 0 to 'models' => 1
 +
#Save file.
 +
 +
*Activate your new module
 +
 +
Now the template will be available in the list of models in the admin settings of proposal.
 +
 +
Test this model (see previous section) before going further.
 +
 +
==For a new module==
 +
Just use the [[https://wiki.dolibarr.org/index.php?title=Module_development#Module_creation_with_the_module_builder |Module Builder]] AGAIN to create your module. When entering the name of a new object to create, you can also check a checkbox to say that you want to manage documents for such new object. In such a case, two templates will be automatically generated (one ODT template and one PDF template).
 +
 +
The templates will be generated with path:
 +
 +
*custom/mymodule/core/modules/doc/pdf_standard_myobject.class.php
 +
*custom/mymodule/core/modules/doc/doc_generic_myobject_odt.class.php
    
=Customize content of your new template=
 
=Customize content of your new template=
Customize the new template. In file pdf_propale_mycompanyblue.modules.php, search for function  
+
Customize the new template:
'Function _pagehead (&$pdf, $fac)'. This defines the header.
+
 
 +
In file pdf_mycompanyblue.modules.php, look for the function '_pagehead()' function. It is the function that manages the display of the header.
 +
 
 +
Look for the '_pagefooter()' function. It is the function that manages the display of the footer.
 +
 
 +
Look for the 'write_file()' function. It is the function that manages the display of the body of PDF.
       
==Library for PDF manipulation==
 
==Library for PDF manipulation==
The library used to create PDF documents in PHP is called FPDF and can be found in htdocs/includes/tcpdf/tcpdf.class.php. This class contains the methods used to generate different parts of documents.
+
The library used to create PDF documents in PHP is called TCPDF and can be found in htdocs/includes/tecnickcom/tcpdf/tcpdf.class.php. This class contains the methods used to generate different parts of documents.
   −
Templates instantiate the FPDF class and use its methods combined with the specific data of the invoice, order etc.
+
Templates instantiate the TCPDF class and use its methods combined with the specific data of the invoice, order etc.
    
We can generally find the following calls into templates that generate PDF documents:
 
We can generally find the following calls into templates that generate PDF documents:
Line 72: Line 129:     
==Frame of scripts==
 
==Frame of scripts==
During the development of version 2.2, the scripts used for generating PDF documents had the following methods (taking as example the model "crabe") inside the class with the model's name:
+
The PHP script used for generating PDF documents had the following methods (taking as example the model "crabe") inside the class with the model's name:
    
*pdf_crabe() - ''Creator of the object pdf''
 
*pdf_crabe() - ''Creator of the object pdf''
Line 82: Line 139:  
*_tableau_versement() - ''Method for drawing table of payment rules''
 
*_tableau_versement() - ''Method for drawing table of payment rules''
 
*_pagefoot() - ''Method for drawing bottom of the page''
 
*_pagefoot() - ''Method for drawing bottom of the page''
      
==Examples of customization==
 
==Examples of customization==
Line 89: Line 145:  
*Add following instructions
 
*Add following instructions
   −
<source lang="php">
+
<syntaxhighlight lang="php">
 
$pdf->Image('\www\htdocs\dolibarr\document\societe\logo.jpg', 10, 5, 60.00);
 
$pdf->Image('\www\htdocs\dolibarr\document\societe\logo.jpg', 10, 5, 60.00);
</source>
+
</syntaxhighlight>
With this example: 10=abscissa, 5=ordinate, 60=with of logo
+
With this example: 10=abscissa, 5=ordinate, 60=width of logo
    
*If the logo is on or outside existing text, remove existing text by commenting the code that outputs the text or by changing its position.
 
*If the logo is on or outside existing text, remove existing text by commenting the code that outputs the text or by changing its position.
Line 98: Line 154:  
===Insert text===
 
===Insert text===
 
Most common function to use
 
Most common function to use
<source lang="php">
+
<syntaxhighlight lang="php">
 
$pdf->setX(float a); // set current x position
 
$pdf->setX(float a); // set current x position
 
$pdf->setY(float b); // set current y position
 
$pdf->setY(float b); // set current y position
Line 105: Line 161:  
$pdf->SetFont('Arial','B',14); // fixe la police, le type ( 'B' pour gras, 'I' pour italique, '' pour normal,...)
 
$pdf->SetFont('Arial','B',14); // fixe la police, le type ( 'B' pour gras, 'I' pour italique, '' pour normal,...)
 
$pdf->MultiCell(60, 8, 'Mon texte", 0, 'L'); // imprime 'Mon texte' avec saut de ligne
 
$pdf->MultiCell(60, 8, 'Mon texte", 0, 'L'); // imprime 'Mon texte' avec saut de ligne
</source>
+
</syntaxhighlight>
 
Note: Origin for setXY functions are the top left corner of page.
 
Note: Origin for setXY functions are the top left corner of page.
    
===Add a PDF Annotation (comment)===
 
===Add a PDF Annotation (comment)===
 
''Left side of the page around the middle:''
 
''Left side of the page around the middle:''
<source lang="php">
+
<syntaxhighlight lang="php">
 
$pdf->Annotation(102, 202, 10, 10, "this is the comment text", array('Subtype'=>'Text', 'Name' => 'Comment', 'T' => 'this is comment author', 'Subj' => 'this is comment title', 'C' => array(255, 255, 0)));
 
$pdf->Annotation(102, 202, 10, 10, "this is the comment text", array('Subtype'=>'Text', 'Name' => 'Comment', 'T' => 'this is comment author', 'Subj' => 'this is comment title', 'C' => array(255, 255, 0)));
</source>
+
</syntaxhighlight>
    
''Right side of the page around the middle:''
 
''Right side of the page around the middle:''
<source lang="php">
+
<syntaxhighlight lang="php">
 
$pdf->Annotation(202, 102, 10, 10, "this is the comment text", array('Subtype'=>'Text', 'Name' => 'Comment', 'T' => 'this is comment author', 'Subj' => 'this is comment title', 'C' => array(255, 255, 0)));
 
$pdf->Annotation(202, 102, 10, 10, "this is the comment text", array('Subtype'=>'Text', 'Name' => 'Comment', 'T' => 'this is comment author', 'Subj' => 'this is comment title', 'C' => array(255, 255, 0)));
</source>
+
</syntaxhighlight>
    
===Add Complementary Attribute (extrafiled)===
 
===Add Complementary Attribute (extrafiled)===
Line 126: Line 182:  
*http://www.fpdf.org/?lang=en
 
*http://www.fpdf.org/?lang=en
 
*List of TCPDF's methods: tcpdf.org/doc/code/classTCPDF.html
 
*List of TCPDF's methods: tcpdf.org/doc/code/classTCPDF.html
      
=Activate your new model=
 
=Activate your new model=
Line 141: Line 196:  
This is probably a font problem, the current font used for generating the PDF cannot handle the foreign characters you are trying to print. So just try to use another font.
 
This is probably a font problem, the current font used for generating the PDF cannot handle the foreign characters you are trying to print. So just try to use another font.
   −
You will find the fonts used by Dolibarr to print PDF inside your Dolibarr folder.../includes/tcpdf/fonts/
+
You will find the fonts used by Dolibarr to print PDF inside your Dolibarr folder.../includes/tecnickcom/tcpdf/fonts/
    
To change the font used for generating PDF, you need to edit the 'main.lang' file of the language you are using (you'll find the file in your Dolibarr.../langs/en_US/main.lang for instance if you use English)
 
To change the font used for generating PDF, you need to edit the 'main.lang' file of the language you are using (you'll find the file in your Dolibarr.../langs/en_US/main.lang for instance if you use English)
Line 149: Line 204:  
*Save the file and try again to generate your PDF.
 
*Save the file and try again to generate your PDF.
   −
If you are unlucky, you can try with more fonts, just go to the TCPDF website sourceforge.net/projects/tcpdf/files/ and download the latest zip package. Then extract only the 'fonts' folder from the zip. Then copy the files in your Dolibarr installation .../includes/tcpdf/fonts/ so you will get more fonts to play with.
+
If you are unlucky, you can try with more fonts, just go to the TCPDF website sourceforge.net/projects/tcpdf/files/ and download the latest zip package. Then extract only the 'fonts' folder from the zip. Then copy the files in your Dolibarr installation .../includes/tecnickcom/tcpdf/fonts/ so you will get more fonts to play with.
    
Also, please make a backup of your files modification.
 
Also, please make a backup of your files modification.
61

edits