2016-01-13 73 views
0
<?php 
    include ('mpdf/mpdf.php'); 
    $mpdf = new mpdf; 
    ob_start(); 
?> 

<html> 
    <head></head> 
    <body> 
     My various content with table, dropdown menu and 2 include files. 
    </body> 
</html> 

<?php 
    $html = ob_get_contents(); 
    ob_end_clean(); 

    $mpdf->Output(); 
    exit; 
?> 

想知道爲什麼這個函數不起作用,只會輸出空的pdf文件。我嘗試了很多方法,但它不起作用。我把這個函數放在我的代碼的開頭,但它總是輸出一個空文件。如何將HTML頁面轉換爲PHP中的PHP

+1

您緩衝到變量$ html和稍後並沒有使用它。不知何故,你必須把它交給$ mpdf對象。但既然你沒有告訴你,你正在使用哪個庫房,沒有人能夠幫助你。檢查你的libaries excamples。 – Daniel

+1

如何通過閱讀'mpdf'圖書館的文檔可以很容易回答的問題得到upvotes? @Daniel是對的,你需要找到你可以傳遞'$ html'的mpdf方法 – Terminus

回答

1

試試這個代碼: -

<?php 
     $html = ob_get_contents(); 
     ob_end_clean(); 
     // You need to write html 
     $mpdf->WriteHTML($html); 
     // define path of your output file and set mode 'F' for saving 
     $mpdf->Output('filename.pdf','F'); 
     exit; 
?>