希望得到一些帮助。我正在尝试使用下面的 php 做 4 件事。第一个长块将签名图像添加到我的 sig.pdf 模板。第二块填充我的 template3.pdf 模板中的表单字段。第三块应该合并两个文件。第四块通过电子邮件发送合并的 pdf。
1 和 4 自己工作,2 和 4 自己工作。
将 1、2 和 4 一起创建两个单独的 pdf,但不会发送电子邮件。
3 从不工作。我收到以下错误:
Fatal error: Uncaught exception 'Exception' with message 'object [1] non trouve' in /home/content/.../html/pdf2/fpdf_merge.php:74 Stack trace: #0 /home/content/.../html/pdf2/fpdf_merge.php(214): FPDF_Merge->error('object [1] non ...') #1 /home/content/.../html/pdf2/fpdf_merge.php(615): FPDF_Merge->getObject(Resource id #23, Array, '1') #2 /home/content/.../html/pdf2/fill.php(79): FPDF_Merge->add('qaf.pdf') #3 {main} thrown in /home/content/.../html/pdf2/fpdf_merge.php on line 74
我猜这可能是因为我的 qaf.pdf 有 7 页长,但还没有找到任何文档。
所以我的问题是:
1) 我可以做些什么来使 fpdf_merge.php 与我的两个文档一起工作?
2) 当我同时使用第一个和第二个进程时,为什么我的电子邮件进程不起作用?
我猜我的东西出了问题。但我不知道如何在 php.ini 中解决这个问题。
感谢您提供任何线索!
注意:我删除了评论(其他人的出色工作),只是为了更容易阅读这篇文章。它们保留在我的工作脚本中。
在这里交叉发布:http ://www.fpdf.org/phorum/read.php?f=1&i=60395&t=60395
1:
$s = new signature;
$s->use_template_pdf('signed','sig');
$s->delete_signature();
class signature {
var $pdf;
var $hash;
var $image;
function __construct(){
require('fpdf/fpdf.php');
require('fpdi/fpdi.php');
$this->make_hash();
$this->make_signature();
}
function make_hash(){
$this->hash = uniqid();
}
function make_signature(){
if(isset($_POST['img'])){
$arr = explode(',',$_POST['img']);
$this->image = "image{$this->hash}.png";
if(is_writable(dirname(__FILE__))){
file_put_contents($this->image, base64_decode($arr[1]));
}else{
die('<p>The working directory is not writable, abort.</p>');
}
}
}
function delete_signature(){
if(file_exists($this->image)) @unlink($this->image);
}
function use_template_pdf($filename, $template){
$this->pdf = new FPDI();
$pagecount = $this->pdf->setSourceFile($template.'.pdf');
$tplidx = $this->pdf->importPage(1);
$this->pdf->addPage();
$this->pdf->SetXY(90, 260);
$this->pdf->Write(5,"Signature: ");
$this->pdf->useTemplate($tplidx, 10, 10);
$this->pdf->Image($this->image,125,260,-200);
if(is_writable(dirname(__FILE__))){
$this->pdf->Output($filename.'.pdf', 'F');
}else{
$this->pdf->Output($filename.'.pdf', 'I');
}
$this->pdf = NULL;
}
}
2:
require('fpdm/fpdm.php');
$fields = array(
'cascade' => $_POST['_fid_6'],
'structuretype' => $_POST['_fid_7'],
'marketmanager' => $_POST['_fid_8'],
);
$pdf = new FPDM('template3.pdf');
$pdf->Load($fields, false);
$pdf->Merge();
$pdf->Output('qaf.pdf', 'F');
3:
require('fpdf_merge.php');
$merge = new FPDF_Merge();
$merge->add('qaf.pdf');
$merge->add('signed.pdf');
$merge->output('qaf-final.pdf', 'F');
4:
$to = $_POST['_fid_6'];
$from = "qaf@me.com";
$subject = "Your QAF";
$separator = md5(time());
$eol = PHP_EOL;
$filename = "qaf-final.pdf";
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "Here is your QAF.".$eol;
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
mail($to, $subject, $body, $headers);