2012-09-20 10 views
6

Sunucumda, her sayfaya eklenmiş metne ihtiyaç duyulan bir pdfs bankam var. Dosyayı açmak ve açmak, metni her sayfaya eklemek, dosyayı kapatmak ve tarayıcıya sunmak için fpdf kullanıyorum. Ben bu yaptırabilirsin ben o zaman eklemek gerekir dakikadaMevcut pdf'yi php olarak değiştirmek için fpdf'yi kullanma

$pdf = new FPDI(); 

$pdf->setSourceFile($filename); 
// import page 1 
$tplIdx = $pdf->importPage(1); 
//use the imported page and place it at point 0,0; calculate width and height 
//automaticallay and ajust the page size to the size of the imported page 
$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true); 

// now write some text above the imported page 
$pdf->SetFont('Arial', '', '13'); 
$pdf->SetTextColor(0,0,0); 
//set position in pdf document 
$pdf->SetXY(20, 20); 
//first parameter defines the line height 
$pdf->Write(0, 'gift code'); 
//force the browser to download the output 
$pdf->Output('gift_coupon_generated.pdf', 'D'); 

header("location: ".$filename); 

bu sadece pdf üzerinde herhangi bir yere bazı metinleri koymak ve kaydetmek için çalışır ama hata

FPDF error: You have to add a page first! 

olsun belgenin yerine sadece 1 değil, bunun nasıl emin her sayfaya metin aşağıdaki belgeleri

cevap

9

deneyin okuduktan

require_once('fpdf.php'); 
require_once('fpdi.php'); 

$pdf =& new FPDI(); 
$pdf->AddPage(); 

kullanın sonra şablon olarak bu sayfayı,

$pdf->setSourceFile($filename); 
// import page 1 
$tplIdx = $pdf->importPage(1); 
//use the imported page and place it at point 0,0; calculate width and height 
//automaticallay and ajust the page size to the size of the imported page 
$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true); 

bunu bir döngü içinde kod koyuyor yapmanın bir yolu hataları

+2

sadece Null kullanarak sadece $ x & $ y '$ outPdf-> useTemplate ($ outPdf-> importPage ($ i), null, null, 0, 0, true); Aksi takdirde Sayfaları A4'e keser. – juanmf

5

metinle tüm sayfaları istediğim için, varsa bana bildirin .

// Get total of the pages 
$pages_count = $pdf->setSourceFile('your_file.pdf'); 

for($i = 1; $i <= $pages_count; $i++) 
{ 
    $pdf->AddPage(); 

    $tplIdx = $pdf->importPage($i); 

    $pdf->useTemplate($tplIdx, 0, 0); 


    $pdf->SetFont('Arial'); 
    $pdf->SetTextColor(255,0,0); 
    $pdf->SetXY(25, 25); 
    $pdf->Write(0, "This is just a simple text"); 
} 
İlgili konular