2012-12-12 2 views
1

내가 localhost/invoice에있는 두 개의 파일이 x.phptemplate.php, 명명 한 후, 나는이 같은 URL이 있습니다?PHP 스크립트의 HTML 출력을 PDF로 변환 하시겠습니까?

로컬 호스트/송장/template.php 이름 = wawan

을 어떻게 할 수 출력 페이지를 PDF로 변환 하시겠습니까? 내가 원하는 것은 x.php에 액세스 한 다음 변환 된 template.php을 얻는 것입니다. mpdf를 사용해 보았지만 작동하지 않습니다.

<?php 
include("MPDF54/mpdf.php"); 

$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0); 

$mpdf->SetDisplayMode('fullpage'); 

$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list 

$mpdf->WriteHTML(file_get_contents('template.php?name=wawan')); 

$mpdf->Output(); 
?> 

을 그리고 이것은 template.php입니다 :

여기 x.php

<div> The name is : 
<?php 


echo $_GET[name]; 

?> 
+0

은 무엇 "작동하지 않습니다"무엇을 의미합니까? 어떻게 작동하지 않습니까? 출력이 올바르지 않습니까? 그게 뭐가 잘못 됐어? 오류 메시지가 나타 납니까? 그렇다면 오류 메시지의 내용은 무엇입니까? –

+0

이 게시물을 확인하는 것이 좋습니다. http://stackoverflow.com/questions/391005/convert-html-css-to-pdf-with-php –

답변

1

당신은 output buffering를 사용할 수 있습니다

# Capture the output of the page: 
ob_start(); 

$_GET['name'] = 'wawan'; 

require 'template.php'; 

$content = ob_get_contents(); 

ob_end_clean(); 

# Write the captured HTML to the PDF: 
$mpdf->WriteHTML($content); 
관련 문제