2010-04-09 62 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。這是在谷歌代碼。