php - PHP Fpdi 错误“意外的 T_USE,需要 T_FUNCTION”
问题描述
我正在尝试将两个 pdf 与 fpdi 和 fpdf 合并,但出现错误,我没有找到任何相关信息。我从https://www.setasign.com/products/fpdi/demos/concatenate-fake/获取了基本代码, 我也在使用 CodeIgniter。
有我的代码:
use setasign\Fpdi\Fpdi;
require_once(APPPATH. 'third_party/fpdf/fpdf.php');
require_once(APPPATH. 'third_party/fpdi/src/autoload.php');
$files = array($this->internalURL . "assets/uploadedContent/Test.pdf", $this->internalURL . "assets/uploadedContent/Test.pdf");
$pageCount = 0;
class ConcatPdf extends Fpdi
{
public $files = array();
public function setFiles($files)
{
$this->files = $files;
}
public function concat()
{
foreach($this->files AS $file) {
$pageCount = $this->setSourceFile($file);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$pageId = $this->ImportPage($pageNo);
$s = $this->getTemplatesize($pageId);
$this->AddPage($s['orientation'], $s);
$this->useImportedPage($pageId);
}
}
}
}
$pdf = new ConcatPdf();
$pdf->setFiles($files);
$pdf->concat();
$pdf->Output('I', './assets/uploadedContent/concat.pdf');
我得到了这个错误:
解析错误:语法错误,意外的 T_USE,在第 27 行的 /var/www/sites/*************/public/application/third_party/fpdi/src/Fpdi.php 中期待 T_FUNCTION
错误来自这一行的 Fpdi 文件:
use FpdiTrait;
不知道是我发的还是?
解决方案
您使用的是过时的 PHP 版本。更新到最新版本。FPDI 2 支持 PHP 5.6 及更高版本。
推荐阅读
- macos - macOS Catalina - 无法打开“fse.node”,因为无法验证开发者。在进行 npm run dev 或观看时
- c++ - 将值从另一个数组写入数组,不包括不需要的值c ++
- node.js - 如何执行子聚合来计算每个桶没有值的字段?
- c# - EF Core Bulk Extensions:索引超出 BulkInsert 的范围
- python-3.x - 在 Python 中使用 Pandas 打开一个损坏的 .xls 文件
- excel - 区域大小不同时无法复制和粘贴
- swift - Swift,如何在没有显式转换的情况下将 String 转换为 Int?
- flutter - 我需要取消 Stream
(扑) - python - ValueError:islice() 的停止参数必须为 None 或整数:0 <= x <= sys.maxsize on topic coherence
- php - 获取具有年份和周数的星期几的日期