我是FPDF的新手。
但我在尝试如下。如何使用FPDF从HTML标签创建PDF?
<?php
require('fpdf.php');
include (connection.php)
$result = mysql_query("SELECT * FROM emp");
<!--- I don't know how to add the html tag here -->
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Output();
?>
下面是我的PHP程序
<?php
include (connection.php)
$result = mysql_query("SELECT * FROM emp");
?>
<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td> <?php print $row['FirstName']; ?></td>
<td> <?php print $row['LastName']; ?></td>
</tr>
<?php
}
?>
</table>
<?php
mysql_close($con);
?>
答案 0 :(得分:2)
我认为你应该考虑使用HTML2FPDF
this blog post底部提供的使用示例。
检查其他SO问题:https://stackoverflow.com/questions/910243/how-to-convert-an-html-to-pdf-in-php-using-fpdf-lib-1-6
答案 1 :(得分:0)
将HTML转换为PDF的PHP代码在我的最终工作正常。 以下代码转换网页并将生成的PDF发送到浏览器:
getAllPurchase()
您还可以转换原始HTML代码,只需使用convertHtml()方法而不是convertURI():
require 'pdfcrowd.php';
// create an API client instance
$client = new Pdfcrowd("username", "apikey");
// convert a web page and store the generated PDF into a variable
$pdf = $client->convertURI('http://www.google.com/');
// set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: max-age=0");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"google_com.pdf\"");
// send the generated PDF
echo $pdf;
API还允许您转换本地HTML文件:
$pdf = $client->convertHtml("<body>My HTML Layout</body>");
转到此处下载API Visit