famoser / pdf-generator
一个无依赖项的干净PDF生成器
0.6
2024-01-03 21:50 UTC
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
关于
无任何依赖项生成PDF文件。包含布局引擎以改善对流动内容(例如跨多页的文本)的处理。
composer require famoser/pdf-generator
该软件仍在积极开发中(欢迎贡献!),公共API可能会更改。如果您正在寻找一个更加成熟的项目,请参阅https://github.com/tecnickcom/TCPDF。
入门指南
使用打印机
// 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());
使用布局引擎
// 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());
布局引擎细节
- 布局可以嵌套(例如,您可以在另一个流动中放置一个流动)
width
(height
)包括padding
,但不包括margin
margin
不会与相邻的margin
合并- 在大小计算过程中忽略绘图(例如,
borderWidth
对元素计算出的width
没有影响 - 子元素的
width
(height
)会覆盖父元素的width
(height
)