2010-04-09 82 views
1

我有一个动态的网页,我创建使用HTML和PHP ...我已经有示例代码,可以将静态网页转换为PDF ...但我的问题是我的网页是动态的...所以有一个将我的页面转换为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> 

回答

1

使用PDF打印机。

这是为了你在自己的机器上做还是作为服务器活动?如果只是为了您,请在您喜爱的浏览器中打开该页面并打印为PDF。

如果是服务器,请尝试类似于在浏览器控件中加载它(在Windows上使用.net容易,否则使用Linux上的firefox组件查看选项)并将其打印为PDF。

1

有些图书馆可以让你这样做。

开始您的研究hereFPDFHTML2FPDF

0

我总是推荐wkhtmltopdf。这是在谷歌代码。