2012-03-06 2 views
0

두 개의 이미지 파일을 업로드해야하며 기존 PDF 파일에 추가해야합니다. 나는 FPDF에 대해 읽었으며이 게시판을 따랐다는 것을 근거로 link입니다. 누군가가 간단한 작업 예제/링크를 게시 할 수 있다면 나와 같은 검색 자나 도움이되는 답변을 찾기 위해 같은 경로를 사용하는 사람들에게 도움이 될 것입니다.PHP를 사용하여 기존 PDF 파일에 이미지 파일 삽입

+0

기존 PDF에 이미지 추가 - 기존 페이지 또는 새 페이지에 표시해야합니까? 전자의 경우, 기존의 컨텐츠를 afaik로만 렌더링 할 수 있다는 것을 명심하십시오 - 삽입 된 이미지로 문서를 리플 로우하려면 처음부터 다시 렌더링해야합니다. – halfer

+0

이미지가 기존 페이지에 표시되어야하는 정보 – 125369

+0

위대한 경우, @tonymarschall의 답은 당신을 정렬해야합니다. – halfer

답변

4

에 대해 FPDI이라는 확장명이있는 것 같습니다. http://pranavom.wordpress.com/2011/03/15/modify-pdf-using-fpdffpdi-library/

당신은과 같이 FPDI를 사용하여 이미지를 배치 할 수 있습니다 : 여기에 기존 PDF 수정하는 방법에 대한 블로그 게시물입니다 내가 PHP를 사용하고

$pdf = new FPDI(); 
$pdf->AddPage(); 
$pdf->setSourceFile("MySource"); 
$template = $pdf->importPage(1); 
$pdf->useTemplate($template); 
$pdf->Image('MyImage.jpg', $x, $y, $width, $height); 
$pdf->Output($outputPath, "F"); 
+0

안녕하세요 토니, 내가 언급 한 예를 따랐고 이미지가 포함 된 pdf를 만들 수 있지만 원본 pdf는 단 하나의 페이지로 구성되어 있지만 작성된 pdf는 공백이며 두 번째 페이지에서 내가 원하는 내용을 얻습니다. 어떤 생각을 어떻게 제거하고 첫 번째 페이지에서 필요한 변경 사항을 얻을 수 있습니다. 당신이 이것을 해결할 수 있다면 당신의 대답도 받아 들일 것입니다. 감사합니다. – 125369

+0

확실치 않습니다. 먼저'$ pdf-> AddPage(); '를 제거하십시오. 그러나 이것은 또 다른 질문입니다. – tonymarschall

+0

그것을 지적 해 주셔서 고맙습니다 tony, 답변 수락 :) 단지 한 가지 더 기본적인 질문입니다. 이미지 크기를 늘리거나 줄이는 것이 가능하거나 이미지 크기가 표준입니다. – 125369

1

는, FPDF는 FDF 파일에서 PDF를 생성하고 그런 다음 qrcode 그래픽을 pdf에 삽입하십시오. 빈 pdf에 양식 필드가 내장되어 있고 다른 프로그램에 그래픽을 삽입하면 양식 필드가 지워져 계속 문제가 발생했습니다. 나는 마침내 그것을 알아 냈다. 희망이 같은 고민하는 다른 사람을 도울 수 있기를 바랍니다. var에 이름 중 하나가 당신을 던져이 코드는 잘라 다른 소스의 톤에서 붙여 넣은 연마되지 않은 경우 내가 장례식 가정을 위해 일

)

나는 다음과 같은 라이브러리 http://www.fpdf.org/http://phpqrcode.sourceforge.net/을 사용하고 있습니다

for($count=0;$count<$doc_list_length;$count++){ 

    //create FDF file 
    $id = rand(11111,99999); 
    $filename = $populated_pdf_path . $casenumber.$doc_list[$count].".fdf";  
    $file = fopen($filename,"w"); 
    $filecontents = "%FDF-1.2". PHP_EOL; 
    $filecontents .= "%âãÏÓ" . PHP_EOL; 
    $filecontents .= "1 0 obj" . PHP_EOL; 
    $filecontents .= "<<" .PHP_EOL; 
    $filecontents .= "/FDF << /Fields [ "; 
    $filecontents .= "<</T(name)/V($name)>>"; 
    $filecontents .= "] " . PHP_EOL; 
    $filecontents .= "/F (empty_pdf/$doc_list[$count].pdf) "; 
    $filecontents .= "/ID [ <$id>" . PHP_EOL; 
    $filecontents .= "] >> " . PHP_EOL; 
    $filecontents .= ">> ". PHP_EOL; 
    $filecontents .= "endobj" . PHP_EOL; 
    $filecontents .= "trailer" . PHP_EOL; 
    $filecontents .= "<<" . PHP_EOL; 
    $filecontents .= "/Root 1 0 R" . PHP_EOL . PHP_EOL; 
    $filecontents .= ">>" . PHP_EOL; 
    $filecontents .= "%%EOF"; 
    fwrite($file, $filecontents); 
    fclose($file); 

    //insert image on this document only 
    //generate qrcode 
    if($doc_list[$count] == "checklist"){ 

     $qrCodeFileName = $cemetery."qrcode.png"; 
     if(!file_exists($populated_pdf_path.$qrCodeFileName)){ 
      include('include/phpqrcode/qrlib.php'); 
      $codeContents = "http://www.asuperduperwebaddress.com"; 
      QRcode::png($codeContents, $populated_pdf_path.$qrCodeFileName); 
     } 

     if(!file_exists($populated_pdf_path.$cemetery."qrcode.pdf")){ 
      //make pdf with image 
      require_once('include/fpdf.php'); 
      $image = $populated_pdf_path.$qrCodeFileName; 
      $pdf = new FPDF(); 
      $pdf->AddPage(); 
      $pdf->Image($image, 183, 250, 25, 25, 'PNG'); 
      $pdf->Output($populated_pdf_path.$cemetery."qrcode.pdf"); 
     } 

     //setup file paths for pdf output 
     $tempFile = $populated_pdf_path . $casenumber.$doc_list[$count]."temp.pdf"; 
     $pdfExampleFile = $populated_pdf_path . $casenumber.$doc_list[$count].".pdf"; 
     $pdfFile = $empty_pdf_path . $doc_list[$count] . ".pdf"; 
     if($doc_list[$count] == "checklist") 
     $fdfFile = $filename; 
     $fdfTemplateFile = $filename; 

     //fill pdf 
     $command = "pdftk $pdfFile fill_form $fdfTemplateFile output $tempFile 2> fill_form.log"; 
     passthru($command); 

     //stamp pdf with qrcode 
     $command = "pdftk " . $tempFile . " stamp " . $populated_pdf_path.$cemetery . "qrcode.pdf output " . $pdfExampleFile; 
     passthru($command); 
    } 
    else{ 
     //setup file paths for pdf output 
     $pdfExampleFile = $populated_pdf_path . $casenumber.$doc_list[$count].".pdf"; 
     $pdfFile = $empty_pdf_path . $doc_list[$count] . ".pdf"; 
     if($doc_list[$count] == "checklist") 
     $fdfFile = $filename; 
     $fdfTemplateFile = $filename; 

     //fill pdf 
     $command = "pdftk $pdfFile fill_form $fdfTemplateFile output $pdfExampleFile 2> fill_form.log"; 
     passthru($command); 
    } 

} 
+0

감사. 한 가지 변경 사항은 $ pdf-> Output 호출에 dest 매개 변수가 필요하다는 것입니다. 나는 사용했다 : $ pdf-> Output ("F", $ filename); – NoelHunter

관련 문제