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

塞尔里

我坚持使用fpdf和fpdi。

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

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

我从以下网址获得了此代码的基础:http : //www.setasign.com/products/fpdi/demos/concatenate-fake/

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 ($pageNo == 1) {
                $this->SetXY(55, 94);
                $this->Write(5, 'page01test');
            }
            if ($pageNo == 2) {
                $this->SetXY(55, 94);
                $this->Write(5, 'page02test');
            }
            if ($pageNo == 3) {
                $this->SetXY(55, 94);
                $this->Write(5, 'page03test');
            }
            if ($pageNo == 4) {
                $this->Write(5, 'page04test');
            }
            if ($pageNo == 5) {
                $this->SetXY(55, 94);
                $this->Write(5, 'page05test');
            }
        }           
    }
 }
}


$pdf = new ConcatPdf();
$pdf->setFiles(array("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();

这使我可以在每页上写独特的文本并将其导出为最终文档。可能有更便宜的方法可以执行此操作,但是它可以满足我的需求。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在PHP中使用FPDF / FPDI编辑PDF

FPDF FPDI 如何从不同的 FPDF 类导入页面?

PHP和FPDI / FPDF:致命错误:未捕获的异常:FPDF错误:错误的输出目标

PHP FPDF / FPDI,希伯来语字符反转/镜像。可以解决吗?

FPDF + FPDI自动打印

如何将2个脚本组合在一起?

如何将多个OpenAPI 3规范文件组合在一起?

使用PHP将CSV中数组的不同部分组合在一起?

如何使用jquery appendTo()将列表项和按钮组合在一起?

如何使用 plotly 或 ggplot 将多个饼图与循环组合在一起

为什么我不能在CellTable中使用GWT Button以及如何将单元格按钮与单元格文本组合在一起

将SQL查询组合在一起

将数组元素组合在一起

将正确的值组合在一起

将数据聚合/组合在一起

如何使用python将头文件与数据文件结合在一起?

将SVG文件与悬停组合在一起时,链接不起作用

FFmpeg批处理文件-将单独的文件集与从另一组文件中随机选择的文件组合在一起

将两个单独的输入字段结合在一起使用php搜索

如何将Scala中的每个n元素组合在一起?

如何将多个稀疏矩阵和密集矩阵组合在一起

如何将多个折线图组合在一起

如何将2个折线图组合在一起

您如何针对多个资源/组件将AppState与Reducers组合在一起?

如何将所有单词组合在一起?

如何将 Python 中的值组合在一起?

在Python中,如何将多个轴组合在一起?

Three.js-如何将多个导入的模型组合在一起

如何将 2 个选择元素组合在一起 html