首页 > 解决方案 > 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;

不知道是我发的还是?

标签: phppdffpdffpdi

解决方案


您使用的是过时的 PHP 版本。更新到最新版本。FPDI 2 支持 PHP 5.6 及更高版本。


推荐阅读