我想將html轉換爲使用PHP或JavaScript的PDF。 我有一個HTML文本和圖像兩者。 我已經嘗試使用html2PDF,但在圖像中面臨問題。 如果我使用相對路徑,則不允許創建PDF並拋出有關未找到圖像的錯誤,並使用絕對路徑,它不會在我的網頁視圖中顯示圖像。 所以任何一個有解決它? 是否有任何其他解決方案將HTML轉換爲PDF或圖像?將具有文本和圖像的HTML轉換爲PDF並使用PHP或javascript創建PDF圖像
需要在PDF創建超過1頁,並且還創造了所有的頁圖像
我想將html轉換爲使用PHP或JavaScript的PDF。 我有一個HTML文本和圖像兩者。 我已經嘗試使用html2PDF,但在圖像中面臨問題。 如果我使用相對路徑,則不允許創建PDF並拋出有關未找到圖像的錯誤,並使用絕對路徑,它不會在我的網頁視圖中顯示圖像。 所以任何一個有解決它? 是否有任何其他解決方案將HTML轉換爲PDF或圖像?將具有文本和圖像的HTML轉換爲PDF並使用PHP或javascript創建PDF圖像
需要在PDF創建超過1頁,並且還創造了所有的頁圖像
`你必須創建一個表和打開的PDF內容和鏈接的HTML或PHP文件
<table width="500px" cellpadding="5px" cellspacing="5px" border="1">
<tr bgcolor="#CCCCCC">
<td>Nombre</td>
<td>Apellido</td>
<td>Email</td>
<td>Edad</td>
</tr>
<tr bgcolor="#FF9933">
<td>Antonio</td>
<td>López</td>
<td>[email protected]</td>
<td>25</td>
</tr>
<tr bgcolor="#FF9933">
<td>Sergio</td>
<td>Martínez</td>
<td>[email protected]</td>
<td>47</td>
</tr>
<tr bgcolor="#FF9933">
<td>Natalia</td>
<td>Estrada</td>
<td>[email protected]</td>
<td>22</td>
</tr>
</table>
<p><a href="pdf.php">Ver tabla en PDF</a></p>
**Now only missing the key issue , the content of pdf.php file :**
<?php ob_start(); ?>
<h2>Lista de usuarios</h2>
<table width="500px" cellpadding="5px" cellspacing="5px" border="1">
<tr bgcolor="#CCCCCC">
<td>Nombre</td>
<td>Apellido</td>
<td>Email</td>
<td>Edad</td>
</tr>
<tr bgcolor="#FF9933">
<td>Antonio</td>
<td>López</td>
<td>[email protected]</td>
<td>25</td>
</tr>
<tr bgcolor="#FF9933">
<td>Sergio</td>
<td>Martínez</td>
<td>[email protected]</td>
<td>47</td>
</tr>
<tr bgcolor="#FF9933">
<td>Natalia</td>
<td>Estrada</td>
<td>[email protected]</td>
<td>22</td>
</tr>
</table>
<?php
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html(ob_get_clean());
$dompdf->render();
$pdf = $dompdf->output();
$filename = "ejemplo".time().'.pdf';
file_put_contents($filename, $pdf);
$dompdf->stream($filename);
?>
我希望這可以幫助你
。 `
有幾個程序用PHP,它總是有小錯誤,如果你PDF轉換爲HTML和PHP可以證明「wkhtmltopdf」或「DOMPDF」 aunq可以給你錯誤的表 Which one is the best PDF-API for PHP? 這裏是最好的HTML轉換器
尋找'HTML 2 PDF'其免費http://stackoverflow.com/questions/391005/convert-html-css-to-pdf-with-php?rq=1 – Noman
使用FPDF,我用它一次http://www.fpdf.org/ –
更喜歡使用DOMPDF - [link](https://github.com/dompdf/dompdf)。看看它的文件。它非常易於使用,並且圖像在這方面完美無缺。 – prateekkathal