首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从现有的可编辑pdf编辑PDF

从现有的可编辑pdf编辑PDF
EN

Stack Overflow用户
提问于 2015-11-13 18:54:33
回答 2查看 833关注 0票数 0

我正在做PHP,Codeignitor。我有一个可编辑的pdf。我想填写pdf中的空白字段,如名字,姓氏,电子邮件。我在php中使用了FPDF和FPDI。首先,我包含了fpdf和fpdi文件。创建一个函数。我的代码如下。因为我创建了FPDI对象。

代码语言:javascript
复制
$pdf = new FPDI();
$pdf->AddPage();
$path = base_url().'uploads/test.pdf';
$pdf->setSourceFile($path);
// import page 1 
$tplIdx = $this->pdf->importPage(1);
//use the imported page and place it at point 0,0; calculate width and height
//automaticallay and ajust the page size to the size of the imported page 
$this->pdf->useTemplate($tplIdx, 0, 0, 0, 0, true);
// now write some text above the imported page
$this->pdf->SetFont('Arial', '', '13');
$this->pdf->SetTextColor(0, 0, 0);
//set position in pdf document
$this->pdf->SetXY(20, 20);
//first parameter defines the line height
$this->pdf->Write(0, 'gift code');
//force the browser to download the output
$this->pdf->Output('gift_coupon_generated.pdf', 'D');

请帮帮我。

EN

回答 2

Stack Overflow用户

发布于 2015-11-14 05:36:34

FPDI无法处理PDF表单。表单域在导入过程中丢失,如FAQ中所述

PDF As FPDI不修改

文档,而是将其逐页导入到可与FPDF一起重复使用的结构中,页面内容流之外的所有内容,如表单字段注释,都会丢失。

无论如何,您仍然可以将文本放在导入的页面上。这只是一个手动步骤来解析字段坐标。

票数 1
EN

Stack Overflow用户

发布于 2017-06-15 13:35:32

您可以首先使用ghost脚本平面化文件。然后,您可以使用fpdi导入它。这是你的工作流程的另一个步骤,但质量仍然保持不变。

代码语言:javascript
复制
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=/LeaveColorUnchanged  \
-dAutoFilterColorImages=true \
-dAutoFilterGrayImages=true \
-dDownsampleMonoImages=true \
-dDownsampleGrayImages=true \
-dDownsampleColorImages=true \
-sOutputFile=document_flat.pdf document_original.pdf
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33691103

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档