https://github.com/famoser/pdf-generator
fast pdf generation with a high-level api
https://github.com/famoser/pdf-generator
packagist pdf-generation php
Last synced: 3 months ago
JSON representation
fast pdf generation with a high-level api
- Host: GitHub
- URL: https://github.com/famoser/pdf-generator
- Owner: famoser
- License: mit
- Created: 2019-01-28T19:05:20.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2026-01-31T15:16:38.000Z (5 months ago)
- Last Synced: 2026-02-01T03:14:14.562Z (5 months ago)
- Topics: packagist, pdf-generation, php
- Language: PHP
- Homepage:
- Size: 36.4 MB
- Stars: 17
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pdf-generator
[](./LICENSE)
[](https://github.com/famoser/pdf-generator/actions/workflows/php.yml)
## About
Generates pdf files without any dependencies. Includes a layout engine to handle flow content (e.g. text spanning over
more than one page).
```bash
composer require famoser/pdf-generator
```
This is still under active development ([contributions welcome!](./CONTRIBUTE.md)), and the public API is subject to
change. If you are looking for a more mature project, see https://github.com/tecnickcom/TCPDF.
## Getting started
Using the printer:
```php
// places "Hello world" in the top-left corner of the document.
$document = new Document();
$printer = $document->createPrinter();
$bodyText = new TextStyle(Font::createFromDefault());
$printer->printText('Hello world', $bodyText);
file_put_contents('example.pdf', $document->save());
```
The printer is useful when the exact position of elements is known. For example, for correspondence with fixed layout
(e.g. the address in a letter) or for documents with page numbers. However, for many elements (such as tables)
determining the exact position is cumbersome. For this, layouts are provided.
Using layouts:
```php
// adds a rectangle, followed by "Hello moon".
// placement is decided by Flow, which places elements one-after-the-other.
$flow = new Flow();
$rectangle = new Rectangle(width: 120, height: 80, style: new DrawingStyle());
$flow->addContent($rectangle);
$text = new Text();
$text->addSpan('Hello moon', $bodyText);
$flow->add($text);
$document->add($flow);
file_put_contents('example.pdf', $document->save());
```
The layouts allow to declare *what* needs to be printed, and then takes care of the *where*. Provided are flows, grids,
tables and text.
## Examples
### Invoice
[Code](./examples/invoice.php) | [.pdf](./examples/invoice.pdf)
### Book
[Code](./examples/book.php) | [.pdf](./examples/book.pdf)