Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel edit existing pdf

Tags:

pdf

laravel

edit

I don't know how to edit an existing pdf file with Laravel.

I have found many plugin for create PDF but no one help me in my problem.

Can anyone know how to do it?

This is what I have tried so far

$pdf->AddPage();
$source = $pdf->setSourceFile(asset("assets/images/coupon/source/coupon.pdf"));
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 90);
$pdf->SetXY(40, 0); // Doesn't work
$pdf->Write(0, 'This is just a simple text'); // Doesn't work
$pdf->Output(); // Doesn't work
like image 374
Nolkyz Avatar asked May 13 '16 12:05

Nolkyz


1 Answers

There is no built-in way for Laravel to edit PDFs. You can of course use external libs, such as FPDF with the FPDI extension to modify PDFs - the result is a new PDF file. There is also a paid lib PDFlib that is capable of editing PDFs.

To install FPDF + FPDI in Laravel you just need to run:

composer require setasign/fpdf && composer require setasign/fpdi

This will install the base FPDF lib + the extension FPDI. Afterwards you can create a new instance and edit your PDF with:

$pdf = new \FPDI();
$pdf->setSourceFile('PATH/TO/SOURCEFILE');

Please make yourself comfortable with the FPDI documentation

Update: With FPDI you cannot directly edit a PDF file. All FPDI does is extracting content from a given PDF file into a reusable format - the result is a complete new PDF. This information can also be found in the FAQ of FPDI.

like image 200
codedge Avatar answered Sep 20 '22 11:09

codedge