PDF循环中的图像问题

时间:2011-11-11 18:14:31

标签: image dompdf

我正在使用DOMPDF生成可以包含图像的PDF,而且我遇到了一个奇怪的问题。

PDF是在循环内生成的,需要生成的PDF数量会有所不同。当只有1个PDF生成时一切顺利。图像(或本例中的徽标)插入得很漂亮。 但是当由于某种原因必须生成2个或更多PDF时,图像将被替换为红叉。但是:该批次生成的第一张PDF中的图像完美无缺。所以:PDF#1中的图像完全加载,PDF#2及以上的图像被红十字代替。

我正在使用DOMPDF的最新稳定版本(v0.5.2)。我也用v0.5.1进行了测试,但行为相同。

我正在测试它的服务器在Linux上运行,使用PHP 5.3.8。错误日志中没有错误(我确实启用了错误记录)。

---编辑: 图像的“路径”是绝对URL,而不是绝对或相对(PHP)路径,并且将循环内容输出到浏览器(或普通HTML电子邮件,没有PDF附件),它显示图像(在所有邮件都很完美。

--- edit2: 使用函数在循环结束时刷新所有缓冲区(不幸的是,这不会改变我的问题):

function flush_buffers()
{ 
    ob_end_flush(); 
    ob_flush(); 
    flush(); 
    ob_start(); 
}

我正在使用的循环示例:

for ( $i = 0; $i < count($cert); ++$i )
{
    // load the email-template
    ob_start();
    include($template);
    $content = ob_get_contents();
    ob_end_clean();

    // require dompdf
    include_once('dompdf/dompdf_config.inc.php');

    // set PDF path - inside temp dir
    $newpdf = trailingslashit(realpath(sys_get_temp_dir())).$cert[$i]['coupon'].'.pdf';

    // replace shortcodes with wanted content
    $certificate = preg_replace($shortcodes, $replacements, $certificate);
    $certificate = '<html><body>'.$certificate.'</body></html>'."\n";

    $dompdf = new DOMPDF(); 
    $dompdf->load_html($certificate); 
    $dompdf->set_paper($pageformat, $orientation);
    $dompdf->render();
    save_pdf($newpdf, $dompdf->output()); // save PDF

    @flush_buffers();
}

其中一个短代码是[logo],并且已被img-tag取代。正如我之前提到的:该图像在第一个PDF中正常工作,但在其他PDF中没有。

1 个答案:

答案 0 :(得分:2)

升级到dompdf 0.6beta2解决了这个问题。谢谢Fabien!

相关问题