【问题标题】:Laravel set Pdf ProtectionLaravel 设置 Pdf 保护
【发布时间】:2020-08-19 14:13:00
【问题描述】:

我想在 laravel 5.5 中创建一个函数来为 PDf 文件设置密码。我通过使用库尝试过

use setasign\FpdiProtection\FpdiProtection;
$pdf = new FpdiProtection();
          $pagecount = $pdf->setSourceFile($request->file('file'));
    for ($i = 1; $i <= $pagecount; $i++) {
        $tplidx = $pdf->importPage($i);
      
        $specs = $pdf->getTemplateSize($tplidx);
      
        $pdf->addPage($specs['orientation'], [ $specs['width'], $specs['height'] ]);
        $pdf->useTemplate($tplidx);
    }
    $pdf->setProtection(
        FpdiProtection::PERM_PRINT | FpdiProtection::PERM_COPY,
        'the user password',
        'the owner password'
    );

    $pdf->save($FilePathPdf);

但它不起作用。 它给出以下错误

消息:类型错误:传递给 setasign\Fpdi\Fpdi::getPdfParserInstance() 的参数 1 必须是 setasign\Fpdi\PdfParser\StreamReader 的实例,给定的 Illuminate\Http\UploadedFile 的实例,在 /home/mumar 中调用/Projects/ilovepdf/vendor/setasign/fpdi/src/FpdiTrait.php 在第 178 行

【问题讨论】:

  • 异常说明了问题:它正在寻找一些东西,但得到了其他东西。换句话说,请求给出了一个UploadedFile 对象,但它appears to need 是其中之一:string|resource|StreamReader。 @MihaiCrăiță 答案通过提供路径解决了这个问题。

标签: php laravel-5


【解决方案1】:

尝试传递文件路径:

$pdf->setSourceFile($request->file('file')->path());

【讨论】:

    猜你喜欢
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    • 2018-05-27
    • 2011-11-07
    相关资源
    最近更新 更多