1. Go to this page and download the library: Download tudorr89/pdfcombiner library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tudorr89 / pdfcombiner example snippets
use PdfCombine\PDFCombiner;
$combiner = new PDFCombiner;
$combiner = new \PdfCombine\PDFCombiner();
$combiner
->addFile('/path/to/report.pdf')
->addFile('/path/to/appendix.pdf')
->save('/path/to/combined.pdf');
$content = $combiner
->addFile('/path/to/doc.pdf')
->blob();
// or
$content = $combiner->stream();
use PdfCombine\Contracts\PDFCombinerInterface;
class ReportController
{
public function combine(PDFCombinerInterface $combiner)
{
$combiner
->addFile(storage_path('reports/january.pdf'))
->addFile(storage_path('reports/february.pdf'))
->save(storage_path('reports/q1.pdf'));
return response()->download(storage_path('reports/q1.pdf'));
}
}
use PDFCombine;
PDFCombine::addFile('/path/to/a.pdf')
->addFile('/path/to/b.pdf')
->download('combined.pdf');
$combiner->addFile('/path/to/doc.pdf'); // all pages
$combiner->addFile('/path/to/doc.pdf', [1, 3]); // pages 1 and 3 only
$combiner->addFile('/path/to/doc.pdf', range(5, 10)); // pages 5 through 10
// Named constants
$combiner->withPaperSize(PDFCombinerInterface::SIZE_A4);
$combiner->withPaperSize(PDFCombinerInterface::SIZE_A5);
$combiner->withPaperSize(PDFCombinerInterface::SIZE_A6);
$combiner->withPaperSize(PDFCombinerInterface::SIZE_LETTER);
$combiner->withPaperSize(PDFCombinerInterface::SIZE_LEGAL);
// Or any TCPDF-compatible format string
$combiner->withPaperSize('A3');
$combiner->withPaperSize('Legal');
// Or custom [width, height] array (in the unit defined above)
$combiner->withPaperSize([210, 297]); // A4 in mm