【发布时间】:2016-06-30 19:41:35
【问题描述】:
我的情况比其他人之前回答的要复杂一些。相同的代码,结果是不同的。
工作场景 - 第一步
转到http://renamchristofoletti.com/en/works/covers/
点击缩略图,然后添加 TILL 4 张图片。
点击下载,然后点击下载作品集。
PDF 按预期生成。 =)
错误场景 - 第二步
执行与上述相同的操作,但现在,在缩略图中添加超过 6 个图像。
PDF 收到“无法流式传输 pdf:标头已发送错误”
你选择的图片无关紧要,同样的事情会发生。
DOMPDF 代码
ob_clean();
echo '<html><body>...'; // above html and css goes here
$images2 = str_replace(' ', "", $_COOKIE['rc_folio']);
$images = explode(',', $images2);
$images = array_filter($images);
foreach ( $images as $image ) {
$img_id = get_image_id($image);
$imglocal = wp_get_attachment_metadata( $img_id );
$img_abs_path = ABSPATH . 'wp-content/uploads/' . $imglocal['file'];
list($width, $height) = getimagesize($img_abs_path);
if ($width > $height) {
// Landscape
echo '<div style="page-break-after: always; text-align: center;"><div class="content-line"></div><div class="content-line-2"></div><img src="' . $img_abs_path . '" style="width: 80%; max-width: 80%; height: auto; margin-top: 250px;" /></div>';
} else {
// Portrait or Square
echo '<div style="page-break-after: always; text-align: center;"><div class="content-line"></div><div class="content-line-2"></div><img src="' . $img_abs_path . '" style="width: auto; height: 60%; max-height: 60%; margin-top: 180px;" /></div>';
}
}
echo '</body></html>';
$html = ob_get_contents();
ob_get_clean();
$pdf_path = ABSPATH . 'wp-content/themes/moqueca/dompdf-master/dompdf_config.inc.php';
require_once( $pdf_path );
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper('letter', 'portrait');
$dompdf->render();
$dompdf->stream("renam_christofoletti_customfolio.pdf");
exit();
请任何人澄清一下我的想法吗?我尝试了许多其他解决方案,但没有任何效果。
提前致谢!
【问题讨论】:
-
为什么使用
ob_clean等。我不认为这是推荐的方式。你能把你所有的echo转换成$html .= '并最终使用它吗?如果您仍然收到错误,请告诉我