如何使用 PHP MySQL 创建 PDF 文件?
我是 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);
?>
I am new to FPDF.
But i am trying like below. How can I create a PDF from HTML tags using FPDF?
<?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();
?>
below is my PHP program
<?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);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您应该考虑使用 HTML2FPDF
底部提供的使用示例 此博文。
还要检查另一个问题:https://stackoverflow.com/questions/910243/how-to-convert-an-html-to-pdf-in-php-using-fpdf-lib-1-6
I think you should consider to use HTML2FPDF
Usage example available at the bottom of this blog post.
Check as well this other SO question: https://stackoverflow.com/questions/910243/how-to-convert-an-html-to-pdf-in-php-using-fpdf-lib-1-6
将 HTML 转换为 PDF 的 PHP 代码对我来说效果很好。
以下代码转换网页并将生成的 PDF 发送到浏览器:
您还可以转换原始 HTML 代码,只需使用 ConvertHtml() 方法而不是 ConvertURI():
该 API 还允许您转换本地 HTML 文件:
转到此处下载 API 访问
PHP code to convert HTML to PDF works fine on my end.
The following code converts a web page and sends the generated PDF to the browser:
You can also convert raw HTML code, just use the convertHtml() method instead of convertURI():
The API lets you also convert a local HTML file:
go here for download API Visit