PDFMerger
v0.5.0
用於合併 pdf 的簡單包裝器,適用於 PHP >= 7.2,基於 setasign/fpdi 和 fpdf 庫,受到 clegginabox/pdf-merger 的啟發。
使用 symfony 框架時,您可以使用 tomsgu/pdf-merger-bundle 套件。
composer require tomsgu/pdf-merger
$ pdfCollection = new PdfCollection ();
$ pdfCollection -> addPdf ( ' filename.pdf ' , PdfFile :: ALL_PAGES , PdfFile :: ORIENTATION_PORTRAIT );
$ pdfCollection -> addPdf ( ' filename2.pdf ' , ' 1-4,9 ' , PdfFile :: ORIENTATION_LANDSCAPE );
$ pdfCollection -> addPdf ( ' filename3.pdf ' , ' 1-4,9 ' , PdfFile :: ORIENTATION_AUTO_DETECT );
$ pdfCollection -> addPdf ( ' filename4.pdf ' );
// You can also pass a resource
$ resource = fopen ( ' filename4.pdf ' , ' r ' );
$ pdfCollection -> addPdf ( $ resource );
$ fpdi = new Fpdi ();
$ merger = new PdfMerger ( $ fpdi );
/**
* Available modes: MODE_FILE, MODE_DOWNLOAD, MODE_STRING, MODE_BROWSER
* Orientation: This is a fallback if the orientation wasn't specified when adding pdf.
*/
$ merger -> merge ( $ pdfCollection , ' output.pdf ' , PdfMerger :: MODE_FILE , PdfFile :: ORIENTATION_LANDSCAPE );