Laravel 编辑现有的 pdf
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37209558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel edit existing pdf
提问by Nolkyz
I don't know how to edit an existing pdf file with Laravel.
我不知道如何使用 Laravel 编辑现有的 pdf 文件。
I have found many plugin for create PDF but no one help me in my problem.
我找到了许多用于创建 PDF 的插件,但没有人帮助我解决我的问题。
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
回答by codedge
There is no built-in wayfor Laravel to edit PDFs. You can of course use external libs, such as FPDFwith the FPDIextension to modify PDFs - the result is a new PDF file. There is also a paid lib PDFlibthat is capable of editing PDFs.
有没有内置的方式为Laravel来编辑PDF文件。您当然可以使用外部库,例如带有FPDI扩展名的FPDF来修改 PDF - 结果是一个新的 PDF 文件。还有一个能够编辑 PDF的付费库PDFlib。
To install FPDF + FPDI in Laravel you just need to run:
要在 Laravel 中安装 FPDF + FPDI,您只需要运行:
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:
这将安装基本 FPDF 库 + 扩展 FPDI。之后,您可以创建一个新实例并使用以下命令编辑您的 PDF:
$pdf = new \FPDI();
$pdf->setSourceFile('PATH/TO/SOURCEFILE');
Please make yourself comfortable with the FPDI documentation
请让自己熟悉 FPDI 文档
Update:With FPDI you cannotdirectly 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 FAQof FPDI.
更新:使用 FPDI,您不能直接编辑 PDF 文件。FPDI 所做的只是将给定 PDF 文件中的内容提取为可重复使用的格式——结果是一个全新的 PDF。此信息也可以在FPDI的常见问题解答中找到。