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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With