2011-11-09 11 views
1

は、彼らがこの例を与える:add_objectでHTMLを挿入しますか? <a href="http://code.google.com/p/dompdf/wiki/FAQ" rel="nofollow">dompdf FAQ page</a>オン

<script type="text/php"> 

if (isset($pdf)) { 

    // Open the object: all drawing commands will 
    // go to the object instead of the current page 
    $footer = $pdf->open_object(); 

    $w = $pdf->get_width(); 
    $h = $pdf->get_height(); 

    // Draw a line along the bottom 
    $y = $h - 2 * $text_height - 24; 
    $pdf->line(16, $y, $w - 16, $y, $color, 1); 

    // Add an initals box 
    $font = Font_Metrics::get_font("helvetica", "bold"); 
    $text = "Initials:"; 
    $width = Font_Metrics::get_text_width($text, $font, $size); 
    $pdf->text($w - 16 - $width - 38, $y, $text, $font, $size, $color); 
    $pdf->rectangle($w - 16 - 36, $y - 2, 36, $text_height + 4, array(0.5,0.5,0.5), 0.5); 

    // Add a logo 
    $img_w = 2 * 72; // 2 inches, in points 
    $img_h = 1 * 72; // 1 inch, in points -- change these as required 
    $pdf->image("print_logo.png", "png", ($w - $img_w)/2.0, $y - $img_h, $img_w, $img_h); 

    // Close the object (stop capture) 
    $pdf->close_object(); 

    // Add the object to every page. You can 
    // also specify "odd" or "even" 
    $pdf->add_object($footer, "all"); 
} 

</script> 

私はtextでHTMLを入れてみましたが、それはうまくいきませんでした。 add_objectでHTMLを挿入する方法はありますか?

答えて

-1

はあなただけを使用することはできません:

$dompdf = new DOMPDF(); 
$dompdf->load_html($html); 
$dompdf->render(); 
$dompdf->stream("sample.pdf"); 
+0

いいえすべてのページに追加されるヘッダーを追加しようとしています。 – mpen

1

ありません。インラインスクリプトを使用すると、バックエンドPDFライブラリに直接アクセスしています。あなたは、図書館が許可するものにのみアクセスできます。サポートされている2つのライブラリ(CPDFとPDFLib)は、HTMLの操作をサポートしていません。

他の方法で同じ結果を達成できないとは限りません。 0.6.0リリース(現在はベータ2)は、指定された場所のすべてのページにレンダリングされる固定位置要素をサポートしています。

this answerのサンプルを参照してください。

+0

問題は、残りのページよりも最初のページに別のヘッダーを追加したいということです。 'position:fixed'はすべてのページにそれを加えます。スクリプトの開始時にすべてをスローすると、 'add_object(...、 'add')'と 'nexteven'と 'nextodd'で目的の効果を得ることができますが、HTMLが必要です... – mpen

関連する問題