如何将动态网页转换为 pdf?

发布于 2024-08-28 05:00:07 字数 2236 浏览 16 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生生不灭 2024-09-04 05:00:07

使用 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.

狼性发作 2024-09-04 05:00:07

有一些库可以让您做到这一点。

此处开始您的研究FPDFHTML2FPDF

There are libraries which will allow ou to do this.

Start your research here with FPDF, and HTML2FPDF.

尾戒 2024-09-04 05:00:07

我总是推荐 wkhtmltopdf

I always recommend wkhtmltopdf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文