mPDF SetSourceFile-从临时存储导入PDF

问题描述 投票:0回答:1

我正在尝试使用mPDF导入PDF文件。PDF文件是从其他服务发送的,我最初的想法是使用wrappers。 (最好是php://memory)。

我得到什么错误:

Warning: filesize(): stat failed for php://memory in /var/www/scrm/modules/AOS_PDF_Templates/PDF_Lib/mpdfi/pdf_parser.php on line 181

[mPDF error: Cannot open php://memory !(此文件被打印到浏览器BTW)

我已经检查了PDF:

  • 显示在浏览器中
  • 保存到文件并从中导入

两者均可,所以PDF没问题。

我检查了php://memory的内容,它们同样有效。这是示例代码:

//part of the code, $content is defined earlier (.pdf file content)
$memoryFile = 'php://memory';
$handle = fopen($memoryFile,'r+');
fwrite($handle,$content);
rewind($handle);

/* dump it to string, just to be sure, part of how i was checking that pdf got saved to $memoryFile
   even with this part removed still doesn't work, so no file issue here
$str=  fread($handle,strlen($content)); //str gets filled with expected data
rewind($handle); //rewind for use by mPDF
*/

$pdf = new mPDF;
$pdf->SetImportUse();
$pagecount = $pdf->SetSourceFile($memoryFile);

我想到的解决方案:

  • 保存到常规临时文件(我不想这样做)
  • mPDF是否可以从字符串导入文件? (Google对我没有任何结果)

OS:Ubuntu 18.04 WSL,PHP版本7.2.31,mPDF版本5.7.1

php mpdf php-7.2
1个回答
0
投票

将您的mPDF版本至少升级到8.0.0。

从版本8开始,mPDF使用更新的基础库FPDI 2,该库通常支持从php://memory或任何流中导入文件。

© www.soinside.com 2019 - 2024. All rights reserved.