gpt4 book ai didi

php - 用 PHP 在 PDF 模板文档上书写/绘图

转载 作者:IT王子 更新时间:2023-10-28 23:57:29 26 4
gpt4 key购买 nike

我希望能够使用 PHP 在现有的 pdf 文档上写入/覆盖文本。我希望做的是拥有一个可以充当模板的 pdf 文档,并通过打开模板文档、覆盖相关文本并将结果作为新文档来填补空白。模板文档是单个页面,因此不需要页面合并/操作。

有没有免费的图书馆可以做到这一点?我应该看哪里?我所做的大多数搜索似乎都涉及合并文档/添加页面,而不是将内容覆盖在现有页面上。

谢谢。

*编辑:这是我所做的:1.下载FPDF2.从

下载FPDI + FPDF_TPL

http://www.setasign.de/products/pdf-php-solutions/fpdi/downloads/

以下是一些供 future 流浪者使用的示例代码(改编自 www.setasign.de 上的示例):

<?php 
include('fpdf.php');
include('fpdi.php');

// initiate FPDI
$pdf =& new FPDI();
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile('templatedoc.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page as the template
$pdf->useTemplate($tplIdx, 0, 0);

// now write some text above the imported page
$pdf->SetFont('Arial');
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(25, 25);
$pdf->Write(0, "This is just a simple text");

$pdf->Output('newpdf.pdf', 'D');
?>

最佳答案

看看FPDI Library添加到 FPDF用于模板注释。

它也可以固定到 TCPDF ,另一个流行的 PHP PDF 库。现有的 PDF 被用作页面的基础,而不是空白,之后的过程与常规 PDF 创建相同。

关于php - 用 PHP 在 PDF 模板文档上书写/绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4299315/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com