Custom PDF Invoices

You can customize invoice and quote PDF files using a template file system. You can find these files in the templates directory of the active WHMCS system theme.

Template Files

You can customize the following templates:

  • templates/viewinvoice.tpl controls the system theme invoice template.
  • templates/invoicepdf.tpl controls the PDF version of the invoice.
  • templates/quotepdf.tpl controls quote PDFs.

You can cause a header or footer to automatically repeat on every page of a multi-page PDF invoice or quote by updating the header and footer templates.

If they exist in your theme, the system will include the following system theme template files on every rendered PDF page:

  • invoicepdfheader.tpl
  • invoicepdffooter.tpl

The system only requires the respective header or footer files. For example, for a customized footer on each page, create the invoicepdffooter.tpl file. You must store these files in the same directory as the invoicepdf.tpl system theme template file.

During template processing, Smarty will provide each of these files with the same variables that it provides to invoicepdf.tpl.

If they exist in your theme, the system will include the following template files for every rendered PDF page:

  • quotepdfheader.tpl
  • quotepdffooter.tpl

The system only requires the respective header or footer files. For example, for a customized footer on each page, create the quotepdffooter.tpl file. You must store these files in the same directory as the quotepdf.tpl template file.

During template processing, Smarty will provide each of these files with the same variables that it provides to quotepdf.tpl.

The logo on PDF invoices and quotes is in the /assets/img/ folder. To change this logo, upload the required logo to the /assets/img/ folder. The name of the file should be logo.jpg or logo.png.

You can change the width of the logo image in the invoicepdf.tpl template file. On line 10, adjust the last number (75) before the closing bracket ());). This variable defines the image width.

Editing Text and Content

You can customize the contents of PDF invoices and quotes by adding or removing text, altering the layout, or adding images and formatting.

To do this, edit the invoicepdf.tpl or quotepdf.tpl system theme template files in the active template folder. These files contain all of the code relating to the layout and display in the PDF file.

  • You will need a basic working knowledge of PHP coding to understand and modify the file.
  • The system generates PDFs using TCPDF. For more information, see the TCPDF website.

Adding Custom Fields

To display custom fields on printable and PDF invoices, go to Configuration () > System Settings > Custom Fields. Then, select Show on Invoice.

The following variables are available for use in the invoicepdf.tpl file:

  • $invoiceid — The ID of the invoice.
  • $invoicenum — The custom number of the invoice. Only set this when you have enabled pro forma or sequential invoicing.
  • $datecreated — The creation date of the invoice.
  • $duedate — The due date of the invoice.
  • $datepaid — The paid date and time, if invoice status is Paid.
  • $userid — The client ID number.
  • $clientsdetails["firstname"] — The client information First Name.
  • $clientsdetails["lastname"] — The client information Last Name.
  • $clientsdetails["companyname"] — The client information Company Name.
  • $clientsdetails["fieldname"] — Other client information values, where fieldname is that item’s name.
  • $customfields — An array of Client Custom Fields (for example, $customfields['Custom Field Name']). For more information, see Translating Products.
  • $subtotal
  • $tax
  • $taxrate
  • $credit
  • $total
  • $status — Paid, unpaid, or cancelled.
  • $paymentmethod
  • $notes
  • $companyname — The Company Name.
  • $companyurl — The Default Website URL.
  • $companyaddress — The Company Address.
  • $invoiceitems — An array of invoice items.

You can retrieve more data by running SQL queries from within the PHP template.

Changing or Translating Filenames

Invoices and quotes have default generated filename formats:

  • The default filename for invoices is Invoice-xxx.
  • The default filename for quotes is Quote-xxx.

In both of these filenames, xxx is the ID of the invoice or quote.

To change or translate these, use the WHMCS language files. When you do this, look for these lines:

$_LANG['invoicefilename'] = "Invoice-";
$_LANG['quotefilename'] = "Quote-";

Reducing the File Size of PDFs

The bulk of the file size for PDFs that WHMCS generates come from the embedded font files for UTF-8. Because the UTF-8 charset has a large range of supported characters, these files are larger than, for example, files that use the ISO-8859-1 character set. Unlike UTF-8, ISO-8859-1 only supports A-Z, a-z, 0-9, and other standard characters.

If no clients are using special characters in their names or addresses, the system does not require UTF-8. You can then reduce the size of PDF files by changing the font.

To do this, change PDF Font Family to Helvetica in the Invoices tab at Configuration () > System Settings > General Settings.

Additional Fonts

The standard font may not support certain special characters. WHMCS supplies an alternative font type that supports languages that require these characters (for example, Czech, Russian, Arabic, and Persian).

To change to the alternate font:

  1. Go to Configuration () > System Settings > General Settings.
  2. Select the Invoices tab.
  3. Select Dejavusans for PDF Font Family.
  4. Click Save Changes.

Last modified: October 25, 2024