英文:
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;
...
我不知道是否使用了错误的库(如果有的话),但这两个库的不同文件如下所示:
我目前的情况是这样的:
致命错误:未捕获的错误:在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:
<?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');
The beginning of my Fpdi.php looks like this:
<?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:
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:
<?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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论