1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Merge PDFs

This commit is contained in:
David Bomba 2022-10-31 07:37:52 +11:00
parent a2814ad13b
commit c5a05efdc2
2 changed files with 19 additions and 1 deletions

View File

@ -40,6 +40,7 @@ use App\Models\Invoice;
use App\Models\Quote;
use App\Models\TransactionEvent;
use App\Repositories\InvoiceRepository;
use App\Services\PdfMaker\PdfMerge;
use App\Transformers\InvoiceTransformer;
use App\Transformers\QuoteTransformer;
use App\Utils\Ninja;
@ -588,6 +589,21 @@ class InvoiceController extends BaseController
}
if($action == 'merge' && auth()->user()->can('view', $invoices->first())){
$paths = $invoices->map(function ($invoice){
return $invoice->service()->getInvoicePdf();
});
$merge = (new PdfMerge($paths->toArray()))->run();
return response()->streamDownload(function () use ($merge) {
echo ($merge);
}, 'print.pdf', ['Content-Type' => 'application/pdf']);
}
/*
* Send the other actions to the switch
*/

View File

@ -12,7 +12,9 @@
namespace App\Services\PdfMaker;
use Illuminate\Support\Facades\Storage;
use \setasign\Fpdi\Fpdi;
use setasign\Fpdi\PdfParser\StreamReader;
class PdfMerge
{
@ -25,7 +27,7 @@ class PdfMerge
$pdf = new FPDI();
foreach ($this->file_paths as $file) {
$pageCount = $pdf->setSourceFile($file);
$pageCount = $pdf->setSourceFile(StreamReader::createByString(Storage::get($file)));
for ($i = 0; $i < $pageCount; $i++) {
$tpl = $pdf->importPage($i + 1, '/MediaBox');
$pdf->addPage();