2016-04-14 58 views
0

有誰知道如何在HTML2FPDF PHP庫中包含CSS文件。我能夠生成一個PDF文件,但風格不包括。目前,我正在HTML字符串($ my_html)的標題中附加樣式表。在HTML2FPDF中添加CSS文件

這是我的代碼。

$pdf = new HTML2FPDF(); 
      $pdf->AddPage(); 
      $pdf->WriteHTML($my_html); 
      $pdf->Output('pdffile_.pdf'); 

回答

0

望着Html2fpdf documentantion我沒有發現任何方法,包括額外的文件到PDF輸出文檔,所以我認爲最好的解決辦法是串聯到您的$my_html變量。見:

$my_html .= "<style>\n " . file_get_contents('path/to/style.css') . "</style>"; 

$pdf = new HTML2FPDF(); 
      $pdf->AddPage(); 
      $pdf->WriteHTML($my_html); 
      $pdf->Output('pdffile_.pdf'); 
+0

它不工作,我試過這一個。 – Ninju