Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
FPDF,FPDI-如何使用PHP将单独的文件和唯一的文本组合在一起?_Php_Fpdf_Fpdi - Fatal编程技术网

FPDF,FPDI-如何使用PHP将单独的文件和唯一的文本组合在一起?

FPDF,FPDI-如何使用PHP将单独的文件和唯一的文本组合在一起?,php,fpdf,fpdi,Php,Fpdf,Fpdi,我坚持使用fpdf和fpdi 我正在使用此代码从5个或更多文件创建1个pdf文件(!重要),并希望在每个页面上输入唯一的文本。当前形式的代码将page01test放在每一页上,而不是将page02test放在第2页上,以此类推 导入的每个文档由一页组成 我从以下方面获得此代码的基础: require('fpdf.php'); require('fpdi.php'); 类ConcatPdf扩展了FPDI { public$files=array(); 公共函数setFiles($files) {

我坚持使用fpdf和fpdi

我正在使用此代码从5个或更多文件创建1个pdf文件(!重要),并希望在每个页面上输入唯一的文本。当前形式的代码将page01test放在每一页上,而不是将page02test放在第2页上,以此类推

导入的每个文档由一页组成

我从以下方面获得此代码的基础:

require('fpdf.php');
require('fpdi.php');
类ConcatPdf扩展了FPDI
{
public$files=array();
公共函数setFiles($files)
{
$this->files=$files;
}
公共职能委员会()
{
foreach($this->files AS$file){
$pageCount=$this->setSourceFile($file);
对于($pageNo=1;$pageNo ImportPage($pageNo);
$this->AddPage();
$this->useTemplate($tplIdx);
$this->AddFont('NotoSans','NotoSans.php');
$this->SetFont('NotoSans','',18);
$this->SetTextColor(63,76,89);
如果($pageNo==1){
$this->SetXY(55,94);
$this->Write(5,'page01test');
}
如果($pageNo==2){
$this->SetXY(55,94);
$this->Write(5,'page02test');
}
如果($pageNo==3){
$this->SetXY(55,94);
$this->Write(5,'page03test');
}
如果($pageNo==4){
$this->Write(5,'page04test');
}
如果($pageNo==5){
$this->SetXY(55,94);
$this->Write(5,'page05test');
}
}           
}
}
}
$pdf=新的ConcatPdf();
$pdf->setFiles(数组(“Proposal1.pdf”、“Proposal2.pdf”、“Proposal3.pdf”、“Proposal4.pdf”、“Proposal5.pdf”);
$pdf->concat();
$pdf->Output();

我一直在玩弄这个问题,并通过反复试验找到了答案

require('customervalues.php');
require('fpdf.php');
require('fpdi.php');

class ConcatPdf extends FPDI
{
public $files = array();

public function setFiles($files)
{
    $this->files = $files;
}

public function concat()
{
    foreach ($this->files AS $file) {
        $pageCount = $this->setSourceFile($file);
        for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
            $tplIdx = $this->ImportPage($pageNo);
            $this->AddPage();
            $this->useTemplate($tplIdx);
            $this->AddFont('NotoSans', '', 'notosans.php');
            $this->SetFont('NotoSans', '', 18);
            $this->SetTextColor(63,76,89);
            if ($file == 'Proposal1.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page01test');
            }
            if ($file == 'Proposal2.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page02test');
            }
            if ($file == 'Proposalxl.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page03test');
            }
            if ($file == 'Proposal4.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page04test');
                $this->SetXY(55, 150);
                $this->Write(5, 'page04test2');
            }
            if ($file == 'Proposal5.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page05test');
            }

        }           
    }
}
}

$pdf = new ConcatPdf();
$pdf->setFiles(array("Proposal1.pdf", "Proposal2.pdf","Proposalxl.pdf", "Proposal4.pdf","Proposal5.pdf"));
$pdf->concat();
$pdf->Output();
require('customervalues.php');
require('fpdf.php');
require('fpdi.php');
类ConcatPdf扩展了FPDI
{
public$files=array();
公共函数setFiles($files)
{
$this->files=$files;
}
公共职能委员会()
{
foreach($this->files AS$file){
$pageCount=$this->setSourceFile($file);
对于($pageNo=1;$pageNo ImportPage($pageNo);
$this->AddPage();
$this->useTemplate($tplIdx);
$this->AddFont('NotoSans','NotoSans.php');
$this->SetFont('NotoSans','',18);
$this->SetTextColor(63,76,89);
如果($file=='Proposal1.pdf'){
$this->SetXY(55,94);
$this->Write(5,'page01test');
}
如果($file=='Proposal2.pdf'){
$this->SetXY(55,94);
$this->Write(5,'page02test');
}
如果($file=='Proposalxl.pdf'){
$this->SetXY(55,94);
$this->Write(5,'page03test');
}
如果($file=='Proposal4.pdf'){
$this->SetXY(55,94);
$this->Write(5,'page04test');
$this->SetXY(55150);
$this->Write(5,'page04test2');
}
如果($file=='Proposal5.pdf'){
$this->SetXY(55,94);
$this->Write(5,'page05test');
}
}           
}
}
}
$pdf=新的ConcatPdf();
$pdf->setFiles(数组(“Proposal1.pdf”、“Proposal2.pdf”、“Proposalxl.pdf”、“Proposal4.pdf”、“Proposal5.pdf”);
$pdf->concat();
$pdf->Output();

这使我可以在每页上编写唯一的文本,并将其导出为最终文档。可能有更便宜的方法,但它可以满足我的需要。

您有什么问题吗?对不起,我没有意识到我没有说得很清楚。它在当前的形式下不起作用,我想知道如何修改代码以允许te每个页面上的xt都是唯一的,因此第1页上的page01test、第2页上的page02test等等。代码看起来“ok”…你确定这不是缓存问题吗?尝试通过向URL添加随机get参数来强制浏览器加载新版本。添加get参数时也不起作用。我被难倒了…不是“每个页面上都有唯一的文本”与“每个文档的唯一文本”有很大不同?您的结果与您的初始问题不符。初始问题说明每个文件都有唯一文本,每个文件只有一页,很抱歉,我没有说清楚,但我找不到任何其他方法,因为您所说的“看起来正常”的代码无法工作。
require('customervalues.php');
require('fpdf.php');
require('fpdi.php');

class ConcatPdf extends FPDI
{
public $files = array();

public function setFiles($files)
{
    $this->files = $files;
}

public function concat()
{
    foreach ($this->files AS $file) {
        $pageCount = $this->setSourceFile($file);
        for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
            $tplIdx = $this->ImportPage($pageNo);
            $this->AddPage();
            $this->useTemplate($tplIdx);
            $this->AddFont('NotoSans', '', 'notosans.php');
            $this->SetFont('NotoSans', '', 18);
            $this->SetTextColor(63,76,89);
            if ($file == 'Proposal1.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page01test');
            }
            if ($file == 'Proposal2.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page02test');
            }
            if ($file == 'Proposalxl.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page03test');
            }
            if ($file == 'Proposal4.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page04test');
                $this->SetXY(55, 150);
                $this->Write(5, 'page04test2');
            }
            if ($file == 'Proposal5.pdf') {
                $this->SetXY(55, 94);
                $this->Write(5, 'page05test');
            }

        }           
    }
}
}

$pdf = new ConcatPdf();
$pdf->setFiles(array("Proposal1.pdf", "Proposal2.pdf","Proposalxl.pdf", "Proposal4.pdf","Proposal5.pdf"));
$pdf->concat();
$pdf->Output();