2015-12-14 33 views
5

我有一個來自MySQL DB的動態加載,並且我的頁面URL是http://localhost/far/contractview?ID=137。當我試圖將此頁面轉換爲PDF格式時,出現了一些錯誤,我不知道該如何操作才能將此頁面轉換爲按鈕單擊時的PDF。php將頁面轉換爲pdf加載ID

我在下面列入了我的代碼。我正在使用mpdf

<?php 
require("mpdf60/mpdf.php"); 
$mpdf=new mPDF('application/pdf','Letter-L','','',15,10,16,10,10,10);//A4 page in portrait for landscape add -L. 
$mpdf->debug = true; 
//$mpdf->allow_output_buffering = true; 
//$mpdf->SetHeader('|Your Header here|'); 
//$mpdf->setFooter('{PAGENO}');// Giving page number to your footer. 
$mpdf->useOnlyCoreFonts = true; // false is default 
$mpdf->SetDisplayMode('fullpage'); 
// Buffer the following html with PHP so we can store it to a variable later 
ob_start(); 
?> 
<?php 
//include "contractview.php"; 
include_once "users.php"; 
//This is your php page ?> 
<?php 
$html = ob_get_contents(); 
ob_end_clean(); 
// send the captured HTML from the output buffer to the mPDF class for processing 
$mpdf->WriteHTML($html); 
//$mpdf->SetProtection(array(), 'user', 'password'); uncomment to protect your pdf page with password. 
$mpdf->Output(); 
exit; 
?> 

在此先感謝。

+0

什麼是 「一些錯誤」,你得到? – bIgBoY

+0

SCREAM:錯誤抑制忽略警告:include_once(contractview?ID = 137)[function.include-once]:未能 打開流:結果太大在C:\ wamp \ www \ far \ php-to-pdf.php 15行 – user2989676

+0

這裏需要php-to-pdf.php的代碼。正如你所看到的,你試圖包含一個url而不是一個文件。 – bIgBoY

回答

0
  1. 首先從官方網站下載FPDF。

http://www.fpdf.org/en/dl.php?v=17&f=zip

2.put它進入Web服務器文件夾。

3.使用require與php文件連接。

創建-pdf.php

<?php 
require("fpdf17/fpdf.php"); 

$pdf=new FPDF(); 
//var_dump(get_class_methods($pdf)); 
$pdf->AddPage(); 

//------------------------ 
$pdf->Image("hello.jpg"); 
$pdf->SetFont("arial","B","20"); 

$pdf->Cell(0,20,"hello world",1,1,"C"); 
$pdf->SetFont("arial","I","10"); 

$pdf->Cell(0,30,"Second line Italic",1,1,"C"); 
$pdf->SetFont("arial","B","20"); 

$pdf->Cell(0,40,"thired line",1,1,"C"); 
$pdf->Output(); 
?> 

退房此鏈接https://topdf.org/html-codehttp://php999.blogspot.in/2014/01/pdf-generation-in-php.html