2016-10-20 10 views
0

私はpdfの大部分を持っています。各pdfには多くのページが含まれています。既存のpdfの各ページにフッターを追加する必要があります。fpdiとfpdfを使用して既存のpdfフッターを編集

  1. ファイルをインポートした後にpdfにいくつのページがあるのか​​?
  2. 各ページを自動的に呼び出す関数を作成できますか?

ここでいいえを取得する方法をお勧めします。ファイル内のページ数をループさせ、各ページにフッターを追加する方法は?

答えて

0
$pdf = new FPDI(); 
$filename="Path to the file"; 
// get the page count 
$pageCount = $pdf->setSourceFile($filename); 
// iterate through all pages 
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) { 
    // import a page 
    $templateId = $pdf->importPage($pageNo); 
    // get the size of the imported page 
    $size = $pdf->getTemplateSize($templateId); 

    // create a page (landscape or portrait depending on the imported page size) 
    if ($size['w'] > $size['h']) { 
     $pdf->AddPage('L', array($size['w'], $size['h'])); 
    } else { 
     $pdf->AddPage('P', array($size['w'], $size['h'])); 
    } 

    // use the imported page 
    $pdf->useTemplate($templateId); 

    $pdf->SetFont('Helvetica'); 
    $pdf->SetFontSize(8); 
    $pdf->SetXY(5,0); 
    $pdf->Write(5, "CSM ROLL NO - $roll_no"); 
} 

// Output the new PDF 
$pdf->Output("targetpath",'F'); 
関連する問題