setasign/fpdi
Composer 安装命令:
composer require setasign/fpdi
包简介
FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies a
README 文档
README
❗ This document refers to FPDI 2. Version 1 is deprecated and development is discontinued. ❗
FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF, which was developed by Olivier Plathey. Apart from a copy of FPDF, FPDI does not require any special PHP extensions.
FPDI can also be used as an extension for TCPDF or tFPDF.
Installation with Composer
Because FPDI can be used with FPDF, TCPDF or tFPDF, we haven't added a fixed dependency in the main composer.json file. You need to add the dependency to the PDF generation library of your choice yourself.
To use FPDI with FPDF, include the following in your composer.json file:
{
"require": {
"setasign/fpdf": "1.9.*",
"setasign/fpdi": "^2.6"
}
}
If you want to use TCPDF, you have to update your composer.json to:
{
"require": {
"tecnickcom/tcpdf": "6.11.*",
"setasign/fpdi": "^2.6"
}
}
If you want to use tFPDF, you have to update your composer.json to:
{
"require": {
"setasign/tfpdf": "1.33.*",
"setasign/fpdi": "^2.6"
}
}
Manual Installation
If you do not use composer, just require the autoload.php in the /src folder:
require_once('src/autoload.php');
If you have a PSR-4 autoloader implemented, just register the src path as follows:
$loader = new \Example\Psr4AutoloaderClass; $loader->register(); $loader->addNamespace('setasign\Fpdi', 'path/to/src/');
Changes to Version 1
Version 2 is a complete rewrite from scratch of FPDI which comes with:
- Namespaced code
- Clean and up-to-date code base and style
- PSR-4 compatible autoloading
- Performance improvements by up to 100%
- Less memory consumption
- Native support for reading PDFs from strings or stream-resources
- Support for documents with "invalid" data before their file-header
- Optimized page tree resolving
- Usage of individual exceptions
- Several test types (unit, functional and visual tests)
We tried to keep the main methods and logical workflow the same as in version 1 but please notice that there were incompatible changes which you should consider when updating to version 2:
- You need to load the code using the
src/autoload.phpfile instead ofclasses/FPDI.php. - The classes and traits are namespaced now:
setasign\Fpdi - Page boundaries beginning with a slash, such as
/MediaBox, are not supported anymore. Remove the slash or use a constant ofPdfReader\PageBoundaries. - The parameters $x, $y, $width and $height of the
useTemplate()orgetTemplateSize()method have more logical correct default values now. Passing0as width or height will result in anInvalidArgumentExceptionnow. - The return value of
getTemplateSize()had changed to an array with more speaking keys and reusability: Usewidthinstead ofwandheightinstead ofh. - If you want to use FPDI with TCPDF, you need to refactor your code to use the class
Tcpdf\Fpdi(since 2.1; before it wasTcpdfFpdi) instead ofFPDI.
Example and Documentation
A simple example, that imports a single page and places this onto a new created page:
<?php use setasign\Fpdi\Fpdi; // or for usage with TCPDF: // use setasign\Fpdi\Tcpdf\Fpdi; // or for usage with tFPDF: // use setasign\Fpdi\Tfpdf\Fpdi; // setup the autoload function require_once('vendor/autoload.php'); // initiate FPDI $pdf = new Fpdi(); // add a page $pdf->AddPage(); // set the source file $pdf->setSourceFile("Fantastic-Speaker.pdf"); // import page 1 $tplId = $pdf->importPage(1); // use the imported page and place it at point 10,10 with a width of 100 mm $pdf->useTemplate($tplId, 10, 10, 100); $pdf->Output();
A full end-user documentation and API reference is available here.
setasign/fpdi 适用场景与选型建议
setasign/fpdi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 154.27M 次下载、GitHub Stars 达 1.25k, 最近一次更新时间为 2012 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdf」 「fpdi」 「fpdf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 setasign/fpdi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 setasign/fpdi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 setasign/fpdi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Extended FPDF include FPDF, FPDF Protection, HTML2PDF, etc
Extension of TCPDF library and FPDI library with added convenience methods.
tfpdf
Composer version of Setasign FPDI-Protection
Extended FPDF
FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies a
统计信息
- 总下载量: 154.27M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1280
- 点击次数: 84
- 依赖项目数: 246
- 推荐数: 12
其他信息
- 授权协议: MIT
- 更新时间: 2012-12-06