https://github.com/mzur/invoiscript
Generate simple PDF invoices with PHP
https://github.com/mzur/invoiscript
invoice invoice-pdf php
Last synced: about 1 year ago
JSON representation
Generate simple PDF invoices with PHP
- Host: GitHub
- URL: https://github.com/mzur/invoiscript
- Owner: mzur
- License: mit
- Created: 2021-06-10T18:08:58.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-01-14T08:12:09.000Z (over 1 year ago)
- Last Synced: 2025-03-28T08:51:11.018Z (over 1 year ago)
- Topics: invoice, invoice-pdf, php
- Language: PHP
- Homepage:
- Size: 222 KB
- Stars: 17
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# InvoiScript
Generate simple PDF invoices with PHP.
## Installation
Run:
```bash
composer require mzur/invoiscript
```
## Usage
### Example
```php
use Mzur\InvoiScript\Invoice;
require_once(__DIR__.'/vendor/autoload.php');
$content = [
'title' => 'Invoice No. 1',
'beforeInfo' => [
'Date:',
'June 10, 2021',
],
'afterInfo' => [
'All prices in EUR.',
'',
'This invoice is due on June 20, 2021.',
],
'clientAddress' => [
'Jane Doe',
'Example Street 42',
'1337 Demo City',
],
'entries' => [
[
'description' => 'Hot air',
'quantity' => 11,
'price' => 8,
],
[
'description' => 'Something cool',
'quantity' => 5,
'price' => 20,
],
],
];
$pdf = new Invoice($content);
$pdf->generate('invoice.pdf');
```
This generates the following PDF:
### Styling
Content in `title`, `beforeInfo` and `afterInfo` can be styled with basic HTML-like tags. Example:
```php
$content = [
'title' => 'Invoice No. 1',
'beforeInfo' => [
'Date:',
'June 10, 2021',
],
//...
];
```
Available tags:
- ``: Bold
- ``: Italic
- ``: Underlined
See the [layout section](#layout) for customization of font and font sizes.
### Template
Set a template file:
```php
$pdf = new Invoice($content);
$pdf->setTemplate(__DIR__.'/template.pdf');
```
The template can have multiple pages, which will be used for the matching pages of the invoice. If the invoice has more pages than the template, the last page of the template will be repeated.
### Language
Set the language:
```php
$pdf = new Invoice($content);
$pdf->setLanguage('de');
```
Available languages are `en` and `de`. Default is `en`.
### Variables
Variables can be used in `title`, `beforeInfo` and `afterInfo`. Example:
```php
$content = [
'title' => 'Invoice No. {number}',
'beforeInfo' => [
'Date:',
'{createdDate}',
],
//...
];
$variables = [
'number' => 1,
'createdDate' => 'June 10, 2021',
];
$pdf = new Invoice($content);
$pdf->setVariables($variables);
```
The following variables are always available:
- `{total}`: Total amount of the invoice.
- `{page}`: Current page number.
- `{pages}`: Total number of pages.
### Layout
The default spacings, font, font size etc. can be overridden with a custom layout. Example:
```php
$layout = [
'font' => 'helvetica',
];
$pdf = new Invoice($content);
$pdf->setLayout($layout);
```
See the [source code](src/Invoice.php#L357) for all available layout options and the defaults.
## Acknowledgment
Thanks to the creator(s) of [FPDF](http://www.fpdf.org/) and [FPDI](https://www.setasign.com/products/fpdi/about/)!
