如何将动态网页转换为 pdf?
我有一个使用 html 和 php 创建的动态网页...我已经有可以将静态网页转换为 pdf 的示例代码...但我的问题是我的网页是动态的...那么有没有办法将我的页面转换为 pdf 格式? 无论如何,这是我的代码:
<?php
include_once("../classes/Receipt.php");
include_once("../classes/SalesDetail.php");
include_once("../classes/Business.php");
//session variable
$userID = 1;
$receipt = &new Receipt();
$receipt->queryReceiptInfo($userID);
$receiptID = $receipt->getReceiptID();
$receiptIssueDate = $receipt->getReceiptIssueDate();
$customer = $receipt->getCustomer();
$salesID = $receipt->getSalesID();
$salesDetail = &new SalesDetail($salesID);
$salesDetails = $salesDetail->viewSalesDetail();
//session variable
$businessID = 1;
$business = &new Business('', $businessID);
$business->queryBusinessName();
$businessName = $business->getBusinessName();
$rows = sizeof($salesDetails);
$columns = sizeof($salesDetails[0]);
?>
<table>
<tr>
<td>Receipt No.</td>
<td><?php echo $receiptID; ?></td>
<tr>
<tr>
<td>Date Issued</td>
<td><?php echo $receiptIssueDate; ?></td>
</tr>
<tr>
<td>Business</td>
<td><?php echo $businessName; ?></td>
</tr>
<tr>
<td>Customer</td>
<td><?php echo $customer; ?></td>
</tr>
</table>
<table>
<tr>
<td>Item</td>
<td>Quantity</td>
<td>Sub-Total</td>
</tr>
<?php
$totalPrice = 0;
for ($i = 0; $i < $rows; $i++) {
echo "<tr>";
for($j = 0; $j < $columns; $j++) {
echo "<td>".$salesDetails[$i][$j]."</td>";
}
$totalPrice += (double)$salesDetails[$i][2];
echo "</tr>";
}
?>
<tr>
<td></td>
<td>Total Price</td>
<td><?php echo $totalPrice;?></td>
</tr>
</table>
I have a dynamic webpage that I created using html and php... I already have sample codes that can convert a static web page to pdf... But my problem is my web page is dynamic... So is there a way to convert my page to pdf?
Anyway, here is my code:
<?php
include_once("../classes/Receipt.php");
include_once("../classes/SalesDetail.php");
include_once("../classes/Business.php");
//session variable
$userID = 1;
$receipt = &new Receipt();
$receipt->queryReceiptInfo($userID);
$receiptID = $receipt->getReceiptID();
$receiptIssueDate = $receipt->getReceiptIssueDate();
$customer = $receipt->getCustomer();
$salesID = $receipt->getSalesID();
$salesDetail = &new SalesDetail($salesID);
$salesDetails = $salesDetail->viewSalesDetail();
//session variable
$businessID = 1;
$business = &new Business('', $businessID);
$business->queryBusinessName();
$businessName = $business->getBusinessName();
$rows = sizeof($salesDetails);
$columns = sizeof($salesDetails[0]);
?>
<table>
<tr>
<td>Receipt No.</td>
<td><?php echo $receiptID; ?></td>
<tr>
<tr>
<td>Date Issued</td>
<td><?php echo $receiptIssueDate; ?></td>
</tr>
<tr>
<td>Business</td>
<td><?php echo $businessName; ?></td>
</tr>
<tr>
<td>Customer</td>
<td><?php echo $customer; ?></td>
</tr>
</table>
<table>
<tr>
<td>Item</td>
<td>Quantity</td>
<td>Sub-Total</td>
</tr>
<?php
$totalPrice = 0;
for ($i = 0; $i < $rows; $i++) {
echo "<tr>";
for($j = 0; $j < $columns; $j++) {
echo "<td>".$salesDetails[$i][$j]."</td>";
}
$totalPrice += (double)$salesDetails[$i][2];
echo "</tr>";
}
?>
<tr>
<td></td>
<td>Total Price</td>
<td><?php echo $totalPrice;?></td>
</tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 PDF 打印机。
这是让您在自己的计算机上执行还是作为服务器活动执行?如果适合您,请在您喜欢的浏览器中打开页面并打印为 PDF。
如果它用于服务器,请尝试将其加载到浏览器控件中(在 Windows 上使用 .net 很容易,否则在 Linux 上查看使用 firefox 组件的选项)并使其“打印”为 PDF。
Use a PDF printer.
Is this for you to do on your own machine or as a server activity? If it's just for you, open the page in your favorite browser and print to PDF.
If it's for a server, try something like loading it in a browser control (easy with .net on windows, otherwise look at options using firefox components on linux) and get it to 'print' to PDF.
有一些库可以让您做到这一点。
在此处开始您的研究FPDF 和 HTML2FPDF。
There are libraries which will allow ou to do this.
Start your research here with FPDF, and HTML2FPDF.
我总是推荐 wkhtmltopdf
I always recommend wkhtmltopdf