我正在使用 TCPDF 生成 PDF,然后通过电子邮件发送 PDF。它适用于 windows、gmail 等,但无法在 ipad 上打开。ipad 说它不是有效的 pdf 格式。
我也有一些用户报告说它不会在他们的机器(Windows 机器)上打开。我看不出代码有什么问题,绝望中我尝试调整格式以删除 UTF 编码,但没有任何区别。
我不确定这是否只是 ipad 问题、字体问题或其他问题。它已经让我把头发扯了一段时间了。我通过 pdfHarmony 运行它,它没有报告任何错误。
我的代码是:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'ISO-8859-1', false);
// $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('XX XX XX');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData('pdfheader.jpg', '190', '', '',array(0,0,0), array(255,255,255) );
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins('10', '50', PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin('0');
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setFontSubsetting(true);
$pdf->SetFont('helvetica', '', 12, '', true);
$pdf->AddPage();
$dateNow = date('d-m-Y');
$html = '<br/><br/><br/><br/><br/><br/>
<h1>Order Form: Conference Ticket</h1>
<p>Date: '.$dateNow.'</p>
<p>Your email address:'.$payer_email.'</p>
<p>Thank you for your order.</p>
<p>Please print this page and bring it with you, as it will be required for registration.</p>
<p> </p>';
for($xx=0;$xx<$quantity;$xx++){
$html="";
$html.='
<div style="page-break-inside:avoid;">
<p></p>
<table>
<tr>
<td style="width:20%"> </td>
<td style="border:1px solid #000000;text-align:center;width:60%">
<h2>Steve Brady brings God’s Word</h2>
<h2>Men’s Conference</h2>
<p style="text-align:center;line-height:10%">Saturday XX November 2013</p>
<p style="text-align:center;line-height:10%">‘Living for Christ – Faith, Work and Family’</p>
<p style="text-align:center;line-height:10%">10.00 am – 13.00 pm</p>
<p style="text-align:center;line-height:10%">(Tea/coffee & registration from 9.30 am)</p>
<p style="text-align:center;line-height:10%">XX Evangelical Church</p>
<p style="text-align:center;line-height:10%">X X Road</p>
<p style="text-align:center;line-height:10%">XX – XX XX Xx</p>
<p style="text-align:center;line-height:100%">Ticket Priced £5.00</p>
<p style="text-align:center;line-height:100%">Ticket number: ';
$ticketNumber = sprintf('%04d', $ticketIdIs);
$html .= $ticketNumber;
$html .='</p>
</td>
<td style="width:20%"> </td>
</tr>
<tr><td>
<td>';
$textIs = $name."-".$ticketNumber;
$html.='</td>
<td></td>
</table>
';
$pdf->writeHTML($html, true, false, true, false, '');
$style = array(
'position' => '',
'align' => 'C',
'stretch' => false,
'fitwidth' => true,
'cellfitalign' => '',
'border' => true,
'hpadding' => 'auto',
'vpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255),
'text' => true,
'font' => 'helvetica',
'fontsize' => 8,
'stretchtext' => 4
);
//$pdf->Cell(0, 0, 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9', 0, 1);
// $pdf->write1DBarcode($textIs, 'C39', '', '', '', 18, 0.4, $style, 'N');
$pdf->AddPage();
}
// $db->close();
$html2='
<div style="page-break-inside:avoid;">
<p>We look forward to you joining with us for a great day listening to God's Word.</p>
<h2>My name</h2><p></p><p></p>
<p style="text-align:center;color:#548dd4;line-height:10%">XX</p>
<p style="text-align:center;color:#548dd4;line-height:10%">XX is a company limited by guarantee, registered in XX.</p>
<p style="text-align:center;color:#548dd4;line-height:10%">Company No. XX - XX Charity No. XX.</p>
<p style="text-align:center;color:#548dd4;line-height:10%">Registered Office: XX.</p>
<p></p>
</div></div>
';
$pdf->writeHTML($html2, true, false, true, false, '');
// Print text using writeHTMLCell()
/*$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='50', $html, $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=false);*/
//*************************************************************************
//end
//*************************************************************************
//*************************************************************************
//This function allows sending of the email with the ticket details
//
//*************************************************************************
$to = "myemail@gmail.com";
$subject = 'Order Form';
$repEmail = 'myemail@gmail.com';
$fileName = 'orderForm.pdf';
$fileatt = $pdf->Output($fileName, 'E');
$attachment = chunk_split($fileatt);
$eol = PHP_EOL;
$separator = md5(time());
$headers = 'From: Me <'.$repEmail.'>'.$eol;
$headers .= 'MIME-Version: 1.0' .$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
$message = "--".$separator.$eol;
$message .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$message .= "Thank you for ordering tickets to our conference.";
if($quantity>1){
$message .="\n\rPlease open the attached document which contains your ".$quantity." tickets. If there is a problem please get in touch with us.";
$message .= "\n\rPlease print out your tickets and bring them with you on the XX November 2013, we'll need them for registration purposes.";
}else{
$message .="\n\rPlease open the attached document which contains your ticket. If there is a problem please get in touch with us.";
$message .= "\n\rPlease print out the ticket and bring it with you on the 23 November 2013, we'll need it for registration purposes.";
}
$message .= "\n\rThanks for your support and we look forward to meeting with you at the conference.".$eol;
$message .= "\n\rThe CMT Team.".$eol;
$message .= "--".$separator.$eol;
$message .= "Content-Type: application/pdf; name=\"".$fileName."\"".$eol;
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Disposition: attachment".$eol.$eol;
$message .= $attachment.$eol;
$message .= "--".$separator."--";
if (mail($to, $subject, $message, $headers)){
// echo "Email sent";
}
else {
echo "Email failed";
}
?>
抱歉,代码有点长,但它需要包含 tcpdf 创建部分和电子邮件部分。
谢谢
艾伦