2014-03-26 63 views
0
require_once('fpdf.php'); 
require_once('fpdi.php'); 

// initiate FPDI 
$pdf = new FPDI(); 

// set the sourcefile 
$sourceFileName = 'dnb.pdf'; 

//Set the source PDF file 
$pagecount = $pdf->setSourceFile($sourceFileName); 
$i = 1; 
$j = 2; 
$k = 3; 
$l = 4; 
$m = 5; 
// add a page 
$pdf->AddPage(); 
$pdf->AddPage(); 
$pdf->AddPage(); 
$pdf->AddPage(); 
$pdf->AddPage(); 
// import page 
$tplidx = $pdf->ImportPage($i); 
$tplidx = $pdf->ImportPage($j); 
$tplidx = $pdf->ImportPage($k); 
$tplidx = $pdf->ImportPage($l); 
$tplidx = $pdf->ImportPage($m); 
$pdf->useTemplate($tplidx, 10, 10, 200); 
$pdf->SetFont('Arial'); 
$pdf->SetTextColor(0,0,0); 
$pdf->SetFontSize(14); 

$pdf->SetXY(40, 265); 
//$pdf->Write(1, "Download from http://abir.kumarkhali.com"); 
$pdf->SetXY(140, 265); 
//$pdf->Write(1, "Date: " . date("d/m/Y")); 

//$pdf->Image('image-1.jpg',120,240,20,20); 
//$pdf->Image('image-2.jpg',120,260,20,20); 

$pdf->Output(time().'-'.$sourceFileName, "D"); 

我想查看pdf的前五頁。在上面的代碼中,我只能得到第5頁。 只有第5頁的上下文被導入。我可以看到其他4頁空白。請幫助。從php腳本中導入頁面

回答

1

嘗試使用for/while循環需要顯示的網頁...

<?php 

require 'fpdf/fpdf.php'; 
require 'fpdfi/fpdi.php'; 

// initiate FPDI 
$pdf = new FPDI(); 

// set the sourcefile 
$sourceFileName = 'dnb.pdf'; 

//Set the source PDF file 
$pdf->setSourceFile($sourceFileName); 
$pagecount = 5; 

$counter = 1; 
while ($counter <= $pagecount) { 

$pdf->AddPage(); 
$tplidx = $pdf->ImportPage($counter); 

$pdf->useTemplate($tplidx, 10, 10, 200); 
$pdf->SetFont('Arial'); 
$pdf->SetTextColor(0,0,0); 
$pdf->SetFontSize(14); 

$pdf->SetXY(40, 265); 
//$pdf->Write(1, "Download from http://abir.kumarkhali.com"); 
$pdf->SetXY(140, 265); 
//$pdf->Write(1, "Date: " . date("d/m/Y")); 

//$pdf->Image('image-1.jpg',120,240,20,20); 
//$pdf->Image('image-2.jpg',120,260,20,20); 

$counter++; 
} 
$pdf->Output(time().'-'.$sourceFileName, "D"); 
+0

我的代碼。不管怎麼說,多謝拉。 –