2012-05-23 4 views
1

FPDI를 사용하여 기존 PDF 파일을 편집하고 단일 페이지에 적합합니다. ou는 내가 $tplIdx = $pdf->importPage(1); 첫 페이지를 편집하고있는 것을 볼 수 있습니다. 6 페이지의 pdf 파일이있어서 다른 페이지에 2 개의 변수를 추가해야합니다.기존 PDF 여러 페이지 편집 FPDF 및 FPDI를 사용하는 파일

가능합니까? 방법?

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

// initiate FPDI 
$pdf = new FPDI(); 
// add a page 
$pdf->AddPage(); 
// set the sourcefile 
$pdf->setSourceFile('ex.pdf'); 

// import page 1 
$tplIdx = $pdf->importPage(1); 


// use the imported page and place it at point 10,10 with a width of 100 mm 
$pdf->useTemplate($tplIdx, 10, 10, 200); 

// now write some text above the imported page 
$pdf->SetFont('Arial'); 
$pdf->SetTextColor(255,0,0); 
$pdf->SetXY(50, 50); 
$pdf->Write(0, "Ajay Patel"); 

$pdf->Output('newpdf1.pdf', 'D'); 
?> 

감사의 말!

+0

@JA 내가, 내가 모든 페이지를 한 페이지 원하는 6 페이지 PDF 파일과 출력을 가져온 –

답변

11

FPDI를 설치하지 않고 시도하기가 어렵습니다. 그러나 핵심 아이디어는 내가 믿는 다음과 같습니다

<?php 

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

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

    /* <Virtual loop> */ 
    $pdf->AddPage(); 
    $pdf->setSourceFile('ex.pdf'); 
    $tplIdx = $pdf->importPage(1); 

    $pdf->useTemplate($tplIdx, 10, 10, 200); 

    // now write some text above the imported page 
    $pdf->SetFont('Arial'); 
    $pdf->SetTextColor(255,0,0); 
    $pdf->SetXY(50, 50); 
    $pdf->Write(0, "Ajay Patel"); 

    /* </Virtual loop/> */ 

    $pdf->AddPage(); 
    //$pdf->setSourceFile('ex.pdf'); 
    $tplIdx = $pdf->importPage(2); 

    $pdf->useTemplate($tplIdx, 10, 10, 200); // dynamic parameter based on your page 

    $pdf->SetFont('Arial'); 
    $pdf->SetTextColor(255,0,0); 
    $pdf->SetXY(50, 50); 
    $pdf->Write(0, "Ajay Patel2"); 

    $pdf->Output('newpdf1.pdf', 'D'); 
?> 

을이 당신이 코드의 두 번째 블록을 제거하고 루프 (동적 위치뿐만 아니라)에이 나갈 수 있습니다 작동합니다. 여러분의 생각은 나를 위해

나는 단지 게시 대답을 작동 @JA

+0

확인해 주시면 곧 알려 드리겠습니다. –

2

감사합니다 당신은 정말 모든 페이지를 반복하는 setSourceFile의 반환 값의 사용을해야 그들에게

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

// initiate FPDI 
$pdf = new FPDI(); 
// add a page 
$pdf->AddPage(); 
// set the sourcefile 
$pdf->setSourceFile('newpdf.pdf'); 

// import page 1 
$tplidx = $pdf->importPage(1); 
for ($i = 1; $i < 6; $i++) { 
       $tplidx = $pdf->ImportPage($i); 


        $pdf->useTemplate($tplidx, 10, 10, 200); 
        $pdf->AddPage(); 

        $pdf->SetFont('Arial'); 
        $pdf->SetTextColor(0,0,0); 
        $pdf->SetFontSize(8); 

        if ($i==3) { 
         $pdf->SetXY(50, 124); 
         $pdf->Write(1, "Ajay Patel"); 

         $pdf->SetXY(50, 133); 
         $pdf->Write(1, date("d/m/Y")); 
        } 

        if ($i==4) { 
         $pdf->SetXY(50, 171); 
         $pdf->Write(1, "Ajay Patel"); 

         $pdf->SetXY(50, 185); 
         $pdf->Write(1, date("d/m/Y")); 
        } 

       } 

$pdf->Output('newpdf1.pdf', 'D'); 
?> 
0

도움을 다른 :

설명

public int FPDI::setSourceFile (string $filename)

사용 된 문서의 PDF 버전에 따라 결과 문서의 PDF 버전이 상위 버전으로 조정됩니다.

매개 변수

$filename : string // A valid path to the PDF document from which pages should be imported from 

돌아

문서의 페이지 수를 값