famoser / pdf-generator
a clean pdf generator without dependencies
Installs: 1 334
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=8.2
- ext-bcmath: *
- ext-gd: *
- ext-json: *
- famoser/agnes: ^4.2
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.6
- friendsofphp/php-cs-fixer: ^3
- mockery/mockery: ^1.2
- phpunit/phpunit: ^9.5.4
- rector/rector: ^0.18.0
- scrutinizer/ocular: ^1.9
README
About
Generates pdf files without any dependencies. Includes a layout engine to improve handling of flowing content (e.g. text spanning more than one page).
composer require famoser/pdf-generator
This is still under active development (contributions welcome!), 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:
// places "Hello world" at coordinate (15/60) coordinates $document = new LinearDocument(); $bodyText = new TextStyle(Font::createFromDefault()); $printer = $document->createPrinter(0, 15, 60); $printer->printText("Hello world", $bodyText); file_put_contents('example.pdf', $document->save());
Using the layout engine:
// places a 20x40 rectangle, followed by "Hello world.". // placement is decided by Flow. $flow = new Flow(); $rectangle = new Rectangle(new DrawingStyle()); $rectangleContent = new ContentBlock($rectangle); $rectangleContent->setWidth(20); $rectangleContent->setHeight(40); $flow->addContent($rectangleContent); $paragraph = new Paragraph(); $paragraph->add($normalText, "Hello "); $paragraph->add($normalText, "World."); $flow->addContent($paragraph); $document->add($flow); file_put_contents('example.pdf', $document->save());
Layout engine particulars:
- Layouts can be nested (e.g. you can place a flow in another flow)
width
(height
) includes thepadding
, but not themargin
margin
does not collapse with adjacent margins- drawings are ignored during size calculations (e.g.
borderWidth
has no influence on the calculatedwidth
of an element width
(height
) of a child overrideswidth
(height
) of a parent