【问题标题】:mPDF SetSourceFile - import PDF from temporary storagemPDF SetSourceFile - 从临时存储中导入 PDF
【发布时间】:2020-06-15 10:08:15
【问题描述】:

我正在尝试使用 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 没有为我提供任何结果)

操作系统:Ubuntu 18.04 WSL,PHP 版本 7.2.31,mPDF 版本 5.7.1

【问题讨论】:

    标签: php mpdf php-7.2


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      相关资源
      最近更新 更多