fpdf,fpdi,fpdm& fpdf_merge与多页pdf - php冲突

时间:2012-12-20 03:10:09

标签: php pdf-generation fpdf

希望得到一些帮助。我正在尝试使用下面的php做4件事。第一个长块将签名图像添加到我的sig.pdf模板中。第二个块填充我的template3.pdf模板中的表单字段。第三个块应合并两个文件。并且第4个块通过电子邮件发送合并的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中解决这个问题。

感谢任何线索!!

注意:我删除了评论(其他人的优秀作品),只是为了更容易阅读这篇文章。它们保留在我的工作脚本中。

在此处交叉发布: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);

0 个答案:

没有答案