【发布时间】: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ță 答案通过提供路径解决了这个问题。