Laravel edit existing pdf

馋奶兔 提交于 2019-12-10 09:45:56

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/37209558/laravel-edit-existing-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!