2016-10-20 7 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');