Laravel编辑现有的pdf [英] Laravel edit existing pdf

查看:579
本文介绍了Laravel编辑现有的pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何使用Laravel编辑现有的pdf文件.

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

我发现有许多用于创建PDF的插件,但是没人能帮助我解决问题.

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

有人知道怎么做吗?

这是我到目前为止尝试过的

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

推荐答案

Laravel无法没有内置方式编辑PDF .您当然可以将外部库(例如 FPDF )与 PDFlib 能够编辑PDF.

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.

要在Laravel中安装FPDF + FPDI,只需运行:

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

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

这将安装基本的FPDF库+扩展名FPDI.然后,您可以创建一个新实例并使用以下命令编辑PDF:

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');

请熟悉 FPDI文档

更新: 使用FPDI,您不能直接编辑PDF文件. FPDI所做的一切都是从给定的PDF文件中提取内容为可重用的格式-结果是一个完整的新PDF.此信息也可以在常见问题解答.

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.

这篇关于Laravel编辑现有的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆