1、composer require rguedes/pdfmerger
2、use PDFMerger
3、开始合并
public function hebingpdf(){ $pdfs = [ "upload/7.pdf", "upload/aa.pdf" ]; $saveFilename = "merage.pdf"; $pdf = new \PDFMerger(); foreach ($pdfs as $index => $fullPath) { $pdf->addPDF($fullPath); } $result=$pdf->merge('file', $saveFilename); halt($result);//true }
有的时候pdf有横板和竖版,会造成内容丢失,解放方案:
$pdf->addPDF('path/to/source/file.pdf', 'all', 'vertical') $pdf->addPDF('path/to/source/file2.pdf', 'all', 'horizontal');