2012-12-12 100 views
1

我已經位於localhost/invoice兩個文件名爲x.phptemplate.php, 後來才知​​道有這樣一個URL:將PHP腳本的HTML輸出轉換爲PDF?

本地主機/發票/ template.php文件名= wawan

我怎樣才能將輸出頁面轉換爲PDF?我想要的是訪問x.php,然後得到轉換template.php。我嘗試使用mpdf,但它不起作用。

這裏的x.php

<?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

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