mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Merge PDFs
This commit is contained in:
parent
a2814ad13b
commit
c5a05efdc2
@ -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
|
||||
*/
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user