2017-11-23 7 views
-2

PHP 코드를 사용하여 PDF를 병합하고 싶습니다. 그래서 일부 사이트에서이 코드를 사용했지만이 코드는 나를 위해 작동하지 않습니다. 'PDFMerger'클래스를 찾을 수 없으므로 오류가납니다. 이 코드를 실행 한 후에도 출력 폴더가 여전히 비어 있습니다. xampp을 사용하여 localhost에서 코드를 실행하고 있습니다. 당신은 병합이 기능을 사용할 수 있습니다PHP 코드를 사용하여 PDF 병합

<?php 
    include 'PDFMerger.php'; 

    $pdf = new PDFMerger; 

    $pdf->addPDF('D:/sample/pdf-1.pdf', 'all') 
     ->addPDF('D:/sample/pdf-2.pdf', 'all') 
     ->addPDF('D:/sample/pdf-3.pdf', 'all') 
     ->merge('file', 'D:/output/merged.pdf'); 
?> 

답변

1

,

/** 
* Used to merge list of pdf files to make it one 
* @param array $files array of files which are to be merged 
* @param string $action download is currently we implemented, rest you can modify the code 
* @param integer $page  number of pages need to fetched from every pdf 
* @param string $filename name of file for pdf which is merged one 
* @return void 
*/ 
function merge_pdf($files = [], $action = '', $page = 1, $filename = '') 
{ 
    require base_path('vendor/autoload.php'); 
    $pdf = new \Jurosh\PDFMerge\PDFMerger; 
    foreach ($files as $key => $file) { 
     $pdf = $pdf->addPDF($file, $page, $key); 
    } 
    // call merge, output format `file` 
    if ($action == 'download') { 
     $pdf->merge('download', $filename); 
    } 
} 

은 여기에 연결되는 패키지는 오래된 종속성을 사용하는 문서 link

+0

입니다. 나는 최신 버전을 제안 할 것이다. FPDI를 사용하는 간단한 연결 스크립트는 예를 들어. [여기] (https://www.setasign.com/products/fpdi/demos/concatenate-fake/). –