2011-11-09 3 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 라이브러리에 직접 액세스합니다. 도서관이 허용하는 것에 만 접근 할 수 있습니다. 지원되는 두 라이브러리 (CPDF 및 PDFLib)는 HTML 작업을 지원하지 않습니다.

다른 방식으로 동일한 결과를 얻을 수 없다는 것은 아닙니다. 0.6.0 릴리스 (현재 베타 2)는 지정된 위치의 모든 페이지에 렌더링되는 고정 위치 요소를 지원합니다.

this answer의 샘플을 참조하십시오.

+0

문제는 나머지 페이지보다 첫 번째 페이지에 다른 머리글을 추가하려고합니다. 'position : fixed'는 모든 페이지에 그것을 추가합니다. 내가 스크립트의 시작 부분에 모든 것을 던지면'add_object (..., 'add')'와 'nexteven'과 'nextodd'로 원하는 효과를 얻을 수 있지만 HTML이 필요하다. – mpen