【问题标题】:PHP and FPDI/FPDF: Fatal error: Uncaught Exception: FPDF error: Incorrect output destinationPHP 和 FPDI/FPDF:致命错误:未捕获异常:FPDF 错误:输出目标不正确
【发布时间】:2017-08-18 09:57:44
【问题描述】:

我有一个 PDF 文件,我想用 FPDI/FPDF 添加一个新页面

致命错误:未捕获异常:FPDF 错误:输出不正确 目的地: C:\wamp\www\pdf\fpdi\fpdf.php 中的 outfiles/111111.pdf 第 271 行(!)异常:FPDF 错误:输出目标不正确: 第 271 行 C:\wamp\www\pdf\fpdi\fpdf.php 中的 outfiles/111111.pdf

require_once('fpdi/fpdf.php');
require_once('fpdi/fpdi.php');

foreach(glob('infiles/*.pdf') as $file)
{
    $filename = basename($file);
    $fileout = 'outfiles/' . $filename;
    //echo $fileout;
    $out = new FPDI();

    $pagecount = $out->setSourceFile($file);

    for($i = 1; $i <= $pagecount; $i++)
    {
        $tpl = $out->importPage($i); 

        $out->addPage($format);
        $out->useTemplate($tpl);

        if($i < $pagecount)
        {
            $out->addPage($format);
        }
    }

    $out->Output($fileout);
}

【问题讨论】:

    标签: php pdf fpdf fpdi


    【解决方案1】:

    Output() 方法要求第一个参数是目标,snd 参数是文件名。

    所以只需将行更改为:

    $out->Output('F', $fileout);
    

    此外,您应该知道您不能使用 FPDI 修改 PDF 文档,但是您可以将页面导入到可重用的结构中。您生成的 PDF 是一个全新的 PDF 文档,您没有在原始文档中添加新页面。

    【讨论】:

      猜你喜欢
      • 2018-04-27
      • 1970-01-01
      • 2014-08-29
      • 2019-10-10
      • 2021-05-01
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多