1. Go to this page and download the library: Download johind/collate 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/ */
johind / collate example snippets
return [
// Path to the qpdf binary (default: 'qpdf')
'binary_path' => env('COLLATE_BINARY_PATH', 'qpdf'),
// Default filesystem disk for reading/writing PDFs (default: null, uses your app's default disk)
'default_disk' => env('COLLATE_DISK'),
// Directory for temporary files during processing (automatically cleaned up)
'temp_directory' => env('COLLATE_TEMP_DIR', storage_path('app/collate')),
];
use Johind\Collate\Facades\Collate;
// Prepare an uploaded document for archival
Collate::open($request->file('document'))
->addPages('legal/standard-terms.pdf')
->withMetadata(title: 'Client Report 2025')
->encrypt('client-password')
->toDisk('s3')
->save('reports/final.pdf');
// Merge and optimize multiple files for web viewing
Collate::merge('cover.pdf', 'chapter-1.pdf', 'chapter-2.pdf')
->overlay('branding/watermark.pdf')
->linearize()
->save('book.pdf');
use Johind\Collate\Facades\Collate;
$pending = Collate::open('invoices/2024-001.pdf');
public function show()
{
return Collate::open('invoice.pdf');
}
Collate::merge(
'documents/cover.pdf',
'documents/chapter-1.pdf',
'documents/chapter-2.pdf',
)->save('documents/book.pdf');
// Also accepts a single array of files
Collate::merge(['doc1.pdf', 'doc2.pdf'])->save('merged.pdf');
$pdf = Collate::inspect('document.pdf');
$pdf->isEncrypted(); // true if the document is encrypted
$pdf->hasPassword(); // true if a password is / PageSize { width: 612.0, height: 792.0 }
$pdf->pageSize(3); // dimensions of a specific page
use Johind\Collate\PendingCollate;
PendingCollate::macro('stamp', function () {
return $this->overlay('assets/stamp.pdf');
});
Collate::open('contract.pdf')->stamp()->save('stamped.pdf');
use Johind\Collate\Collate;
Collate::macro('openInvoice', function (int $invoiceId) {
return $this->open("invoices/{$invoiceId}.pdf");
});
Collate::openInvoice(2024001)->download();
Collate::open('document.pdf')
->rotate(90)
->encrypt('secret')
->dump(); // dumps the command and continues the chain
Collate::open('document.pdf')
->overlay('watermark.pdf')
->dd(); // dumps the command and stops execution