2013-02-26 22 views
0

可以說我有以下文件:如何從php文件「製作」PDF文件?

layout.php中

<?php 
session_start(); 
?> 
<table width="700" border="1" cellspacing="0" cellpadding="0"> 
    <tr> 
    <th>Id</th> 
    <th>Nombre</td> 
    </tr> 
    <tr> 
    <td><?php echo $_SESSION['id']; ?></td> 
    <td><?php echo $_SESSION['nombre']; ?></td> 
    </tr> 
</table> 

有沒有一種方法,我可以下載該文件,將輸出文件就像你看到它在瀏覽器中的PDF?

我試過,但它沒有工作:

<?php 
session_start(); 

header("Content-type:application/pdf"); 
header("Content-Disposition:attachment;filename=info_user.pdf"); 
readfile('layout.php'); 
?> 
+0

PDF文件是在一個特定的格式,你不能只是做一個這樣的。您需要使用像[dompdf](https://code.google.com/p/dompdf/)或[FPDF](http://www.fpdf.org/)這樣的庫。 – 2013-02-26 17:01:18

+2

不,沒有辦法這樣做,因爲你不能只發送'Content-Type:audio/mpeg3'並得到一首歌。 – 2013-02-26 17:01:52

回答

0

Chrome瀏覽器可以將網頁保存爲PDF格式,如果這可以幫助你。