无法使用Fpdf和Fpdi进行PDF的简单修改。

huangapple go评论79阅读模式
英文:

Can't make a simple modification of a pdf using Fpdf and Fpdi

问题

我需要你的问题,我知道在不同的论坛上已经有很多次提出过,但我无法解决,可能是因为我是新手。如果我解决了一个问题,另一个问题就会出现... 直到我回到我的第一个问题等等...
我只是想尝试使用Fpdi导入PDF并添加文本。
我尝试了很多事情,我都记不清了!

这是我正在做的事情:

<?php
include_once('includes/FPDF/fpdf.php');
include_once('includes/Fpdi/src/autoload.php');

use setasign\Fpdi\Fpdi;

$pdf= new Fpdi();
$pdf-> AddPage();
$pdf->setSourceFile('includes/TCPDF/doc/report.pdf');
$tplAgence = $pdf->importPage(1);
$pdf->SetFont('Arial');
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(20,20);
$pdf->Write(0,"Come on, write something!");
 
$pdf->Output('hourra.pdf','D');

我的Fpdi.php的开头如下:

<?php
namespace setasign\src;

use setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException;
use setasign\Fpdi\PdfParser\PdfParserException;
use setasign\Fpdi\PdfParser\Type\PdfIndirectObject;
use setasign\Fpdi\PdfParser\Type\PdfNull;

class Fpdi extends FpdfTpl
{
    use FpdiTrait;
...

我不知道是否使用了错误的库(如果有的话),但这两个库的不同文件如下所示:

无法使用Fpdf和Fpdi进行PDF的简单修改。

我目前的情况是这样的:

致命错误:未捕获的错误:在C:\xampp\htdocs\testProject\includes\Fpdi\src\Fpdi.php的第22行抛出错误:找不到类"setasign\src\FpdfTpl"。堆栈跟踪:#0 C:\xampp\htdocs\testProject\includes\Fpdi\src\autoload.php(18):require_once() #1 C:\xampp\htdocs\testProject\testPDF.php(25):{closure}('setasign\Fpdi\F...') #2 {main} 在C:\xampp\htdocs\testProject\includes\Fpdi\src\Fpdi.php的第22行抛出

请告诉我是否需要其他信息。实际上,我只需要一个可以用作项目开端的示例。

非常感谢。

英文:

I need your need for a problem which I know was asked a few times in different forum, but that I can't solve, probably because I'm a newbie. If I resolve a problem, another one is coming... until I goes back to my first problem etc...
I'm just trying to import a pdf using Fpdi and add a text.
I tried so many things that I can't remember everything!

This is what I'm doing:

&lt;?php
include_once(&#39;includes/FPDF/fpdf.php&#39;);
include_once(&#39;includes/Fpdi/src/autoload.php&#39;);

use setasign\Fpdi\Fpdi;

$pdf= new Fpdi();
$pdf-&gt; AddPage();
$pdf-&gt;setSourceFile(&#39;includes/TCPDF/doc/report.pdf&#39;);
$tplAgence = $pdf-&gt;importPage(1);
$pdf-&gt;SetFont(&#39;Arial&#39;);
$pdf-&gt;SetTextColor(255,0,0);
$pdf-&gt;SetXY(20,20);
$pdf-&gt;Write(0,&quot;Come on, write something!&quot;);
 
$pdf-&gt;Output(&#39;hourra.pdf&#39;,&#39;D&#39;);

The beginning of my Fpdi.php looks like this:

&lt;?php
namespace setasign\src;

use setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException;
use setasign\Fpdi\PdfParser\PdfParserException;
use setasign\Fpdi\PdfParser\Type\PdfIndirectObject;
use setasign\Fpdi\PdfParser\Type\PdfNull;

class Fpdi extends FpdfTpl
{
    use FpdiTrait;
...

I don't know if I have the wrong libraries (if there are any) but the different files for the 2 libraries are:

无法使用Fpdf和Fpdi进行PDF的简单修改。

What I have at the moment is this:

Fatal error: Uncaught Error: Class "setasign\src\FpdfTpl" not found in C:\xampp\htdocs\testProject\includes\Fpdi\src\Fpdi.php:22 Stack trace: #0 C:\xampp\htdocs\testProject\includes\Fpdi\src\autoload.php(18): require_once() #1 C:\xampp\htdocs\testProject\testPDF.php(25): {closure}('setasign\Fpdi\F...') #2 {main} thrown in C:\xampp\htdocs\testProject\includes\Fpdi\src\Fpdi.php on line 22

Please, let me know if you need anything else. Actually, I just need an example I could use as a beginning for my project.

Thanks a lot

答案1

得分: 2

看起来您修改了FPDI文件。这部分:

namespace setasign\src;

是错误的。
为什么您删除了版权和许可证头以及修改了命名空间?

进行全新安装,然后您就可以使用了。您可以在此处找到原始头文件以进行比较,例如 here

英文:

It looks like you modified files of FPDI. This:

&lt;?php
namespace setasign\src;

...is wrong.
Why did you removed the copyright and license header and modified the namespace?

Do a fresh install and you're ready to go. You can find the original header for comparsion e.g. here.

huangapple
  • 本文由 发表于 2023年3月21日 02:01:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793783.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定