earthlinginteractive/oophpdf
Composer 安装命令:
composer require earthlinginteractive/oophpdf
包简介
An object-oriented wrapper for writing PDF documents using PHP and TCPDF
README 文档
README
An object-oriented wrapper for writing PDF documents using PHP and TCPDF
Description
OOPHPDF is a PHP library that provides an object-oriented interface to common TCPDF drawing methods. Examples of implemented objects include the MultiCell, Image, and a basic Table with Rows that contain cells. Instead of directly calling TCPDF methods to draw items, you create an object that represents the item you want to draw, configure it, query it as needed, then draw it.
Installation
OOPHPDF can be installed as a Composer module. If you're using Composer, you can install it with:
composer require earthlinginteractive/oophpdf
Why?
TCPDF is great for writing PDF documents, but its state-based design can be limiting when writing complex documents.
For example, try writing two MultiCell boxes side-by-side with different fonts, but make the height of both match the height of the tallest, so that they are only as tall as needed to fit the text of both. You'd need to set up the context for each box, determine its height, determine the largest height, then draw both boxes (which involves setting up the context for each again).
This library simplifies the problem by treating each item on the PDF as an object.
Using this library, you would create and configure an object for each box, find the height of each, determine the largest height, set that height on both boxes, then draw them. You're no longer responsible for setting up and restoring context; the objects maintain their own contexts.
Example
This example implements the problem described in the "Why" section, where two boxes of text with different font sizes are written next to each other with the same height.
The code below assumes the TCPDF object is already created with units in inches and a blank page in portrait Letter size. It also assumes you will output the PDF document afterwards. See the full example in example.php.
// create the left box
$leftBox = new OOPHPDF_MultiCell($pdf);
$leftBox
->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.")
->setFontSize(24)
->setFontStyle('B')
->setFillColorArray(array(255, 200, 200)) // light red
->setLn(0)
->setWidth(3.75)
->setHeightToAuto();
// create the right box
$rightBox = new OOPHPDF_MultiCell($pdf);
$rightBox
->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
->setFontSize(16)
->setFontStyle('I')
->setFillColorArray(array(200, 200, 255)) // light blue
->setLn(0)
->setWidth(3.75)
->setHeightToAuto();
// find the height of the tallest box
$maxHeight = max($leftBox->getHeight(), $rightBox->getHeight());
// make both boxes use the tallest height
$leftBox->setHeight($maxHeight);
$rightBox->setHeight($maxHeight);
// draw both boxes
$leftBox->drawAtPosition(0.5, 1);
$rightBox->drawAtPosition(4.25, 1);
earthlinginteractive/oophpdf 适用场景与选型建议
earthlinginteractive/oophpdf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.49k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 earthlinginteractive/oophpdf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 earthlinginteractive/oophpdf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.49k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-05-13