2016-06-30 15 views
0

私のケースは以前に答えたものより少し複雑です。同じコードでは結果は異なります。dompdfエラーストリームすることができないpdf:既に送信されたヘッダ

WORKING CENARIO - 第一ステップ

サムネイル上http://renamchristofoletti.com/en/works/covers/

クリックに移動し、4枚の画像TILL ADD。

「Download」、および「Download Portfolio」をクリックします。

期待どおりのPDFが生成されました。 =)

ERRORのCENARIO - 第二ステップ

サムネイルで6枚の以上の画像を追加し、上記のように、今同じことを行います。

PDFます:

を「PDFをストリーミングすることができませんすでにエラーを送ったヘッダが」あなたが選択している画像とは関係ありません、同じことが起こります。

DOMPDFのCODE

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(); 

誰もがこのことについて私の心を明確にすることができますしてください?私は他の多くのソリューションを試しましたが、何も目にすることはありません。

ありがとうございます!

+0

なぜ、 'ob_clean'などを使うのかは、それが推奨される方法ではないと思います。 'echo'を '$ html。= ''に変換して、それを最後に使用できますか?まだエラーが発生した場合はお知らせください – Dharam

答えて

1

出力バッファーサイズの制限値を超えているようです。

ini_set('output_buffering', true); // no limit 
ini_set('output_buffering', 12288); // 12KB limit 

かは、次のとおりです。これはあなたがバッファサイズを変更することができ、いずれの場合であれば

echo ini_get('output_buffering'); 

:あなたはサイズ制限がoutput_buffering設定パラメータの値をチェックすることであるかどうかを確認することができますあなたの質問へのDharamさんのコメントで指示し、出力のバッファリングに頼るのではなく、直接変数にコンテンツをプッシュ:

$html = '<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 
      $html .= '<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 
      $html .= '<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>'; 
     } 
} 
$html .= '</body></html>'; 
0

ケースは解決しました。私はhtmlのエコーを変更しました。=すべてが完璧に動作します。

ありがとうございました。

関連する問題