Faktura PHP – Generate PDF invoices in PHP

Faktura

Faktura in polish means invoice and this library is created to render pretty invoices in PHP.

Project source code on GitHub: https://github.com/loskoderos/faktura-php

Faktura is a simple standalone PHP library for rendering PDF invoices in PHP. You can easily integrate it into your own project using standard tools like composer. Currently, Faktura depends on xvfb and wkhtmltopdf to create PDF files. Faktura has builtin rendering based on native PHP templates that can be customized with plugin functions.

Sample PDF invoice: https://github.com/loskoderos/faktura-php/blob/master/examples/simple_invoice_pl.pdf

Basic usage

Faktura is simple to use and it lets you to map an invoice structure and customize it to your needs.

use LosKoderos\Faktura\Faktura;
$faktura = new Faktura();
$invoice = $faktura->newInvoice();
$invoice->setInvoiceReference('INV/123/2018');
//...
$invoice->newItem()
    ->setDescription('Some item on the invoice')
    ->setUnitNetPrice(123)
    ;
//...
$faktura->setTemplate('path_to_your_invoice_template.phtml');
$faktura->export($invoice, 'invoice.pdf');

Have a look into examples folder to see the full example: https://github.com/loskoderos/faktura-php/blob/master/examples/simple_invoice_pl.php

Features

  • Standalone library, no external PHP frameworks needed.
  • Easily integrates with others.
  • Builtin templating using native PHP templates.
  • Builtin support for UTF-8 and images.
  • Extend template rendering with custom plugin functions.
  • Invoice structure can be customized, you can add custom fields to fit your needs.
  • Invoice can be serialized to save it in database for accounting purposes.
  • You can easily customize the library with overrides.

Installation

Faktura is still under development, however if you want to try it out you can easily install it with Composer:

composer config minimum-stability dev
composer require loskoderos/faktura-php:dev-master

Before you use it, you need to take care of a couple od system dependencies. You’ll need to install Xvfb and Wkhtmltopdf, on Ubuntu run:

sudo apt-get install xvfb wkhtmltopdf

To confirm, all is good, run the example:

php examples/simple_invoice_pl.php

It should finish without any error and generate examples/simple_invoice_pl.pdf.

Contributing

Contributions are welcome, please submit a pull request.

License

MIT

Lukasz Cepowski

Hi! I'm the person behind Los Koderos. Tech stuff aside, love riding motorbikes, 4x4, offroading, exploring outdoors, cooking and tinkering with other DIY projects. Based in Krakow, Poland.