【问题标题】:TCPDF still not working for meTCPDF 仍然不适合我
【发布时间】:2014-03-08 03:59:05
【问题描述】:

我不确定自己做错了什么。我正在尝试使用 tcpdf 从我的表单中生成 pdf。当我点击提交时,它只是打开一个空白网页,我根本没有收到任何 pdf。当我链接示例以查看是否是安装问题时,它们可以完美运行。我能做些什么来解决这个问题吗?

我的html

<h2>Proto/Addendum Form</h2>
<p>
<form method="post" action="pdfcreate.php">
Job #: <input type="text" name="jobnum">
<br>
Program: <input type="text" name="program"><br />
Ship Date: <input type="text" name="shipdate"><br />
Description: <input type="text" style="height:100px; width:85%" name="description"><br /><br />
Proto Verified By: <input type="text" name="name"><br /><br />
Additional Notes: <input type="text" style="height:100px; width:85%" name="notes"><br />
<br /><br />
<h2>White Stock</h2>
Filename<input type="text" name="filename1" style="width:85%"><br />
Doc size<input type="text" name="Docsize1" size="6">
FC<input type="checkbox" name="fc1" value="fc">
DC<input type="checkbox" name="dc1" value="dc">
Flip<input type="checkbox" name="flip1" value="flip">
Quantity<input type="text" name="quantity1" size="6">
Flip Quantity<input type="text" name="flipqty1" size="6">
<br />

<input type="submit" name="value" value="submit" />
</form>

我的 php:

<?php


// Include the main TCPDF library 
//(search for installation path).

require_once('tcpdf_include.php');


// create new PDF document

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);


// set document information

$pdf->SetCreator(PDF_CREATOR);

$pdf->SetTitle('proto_addendum');

$pdf->SetSubject('jobnum');


// set default header data

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 01', PDF_HEADER_STRING);


// set header and footer fonts

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));


// set default monospaced font

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


// set margins

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);

$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);


// set auto page breaks

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);


// set image scale factor

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);


// ---------------------------------------------------------


// IMPORTANT: disable font subsetting to allow users editing the document

$pdf->setFontSubsetting(false);


// set font

$pdf->SetFont('helvetica', '', 10, '', false);


// add a page

$pdf->AddPage();


//data
$pdf->writeHTMLCell(0,0,0,0, "Job Number ". $_POST["jobnum"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,5, "Program ". $_POST["program"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,10, "Ship Date ". $_POST["shipdate"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,15, "Description ". $_POST["description"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,20, "Proto Verified By ". $_POST["name"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,25, "Additional Notes ". $_POST["notes"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,30, "File Name". $_POST["filename1"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,35, "Doc Siize ". $_POST["Docsize1"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,40, "FC ". $_POST["fc1"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,45, "DC ". $_POST["dc1"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,50, "Flip ". $_POST["flip1"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,55, "Quantity ". $_POST["quantity1"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);

$pdf->writeHTMLCell(0,0,0,60, "Flip Quantity ". $_POST["flipqty1"], $border=0, $ln=0,   $fill=false, $reseth=true, $align='', $autopadding=true);




// Add Javascript code

$pdf->IncludeJS($js);


// ---------------------------------------------------------


//Close and output PDF document

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

?>

编辑 - 谢谢...这是我收到的警告:警告:require_once(tcpdf_include.php):无法打开流:第 26 行的 C:\inetpub\wwwroot\intranet2\pdfcreate.php 中没有这样的文件或目录致命错误: require_once():在第 26 行的 C:\inetpub\wwwroot\intranet2\pdfcreate.php 中打开所需的 'tcpdf_include.php' (include_path='.;C:\php\pear') 失败

edit2 - 移动了一些东西,现在这是我收到的错误:致命错误:在线 C:\inetpub\wwwroot\intranet2\pdfcreate.php 中找不到类 'TCPPDF' 31

edit3 谁能帮忙?我卡住了。

edit4 我可能会到达某个地方。将 tcpdf_include.php 更改为 tcpdf.php 然后: 注意:未定义索引:第 117 行 C:\inetpub\wwwroot\intranet2\pdfcreate.php 中的 fc1 注意:第 119 行未定义索引:C:\inetpub\wwwroot\intranet2\pdfcreate.php 中的 dc1 注意:未定义索引:flip1在 C:\inetpub\wwwroot\intranet2\pdfcreate.php 第 121 行 TCPDF ERROR: Some data has been output, can't send PDF file

我相信我的问题是复选框。如果没有设置,有没有办法通过?

edit 5 我修复了复选框问题,但我仍然收到“TCPPDF 错误:一些数据已经输出,无法发送 PDF 文件”

【问题讨论】:

  • 空白页(或“500 内部服务器错误”状态码)意味着您的脚本正在抛出错误,但您尚未配置 PHP 以显示错误消息。这是您在更进一步之前需要解决的问题;如果没有错误消息的帮助,就不可能正确编码。这是brief explanation
  • 请注意,当您有更多信息时,您可以(并且应该)编辑您的问题。不管怎样,错误信息很清楚...
  • 找不到这个文件require_once('tcpdf_include.php');
  • “没有这样的文件或目录”的意思是:你没有tcpdf_include.php在与pdfcreate.php相同的目录中。
  • 对于edit 4/5,偷懒的方法就是关闭错误显示。吐出的通知会阻止 TCPDF 发送 PDF 内容类型标头。或者,在尝试访问之前使用isset 检查$_POST 密钥是否存在。

标签: php tcpdf


【解决方案1】:

要使用 require_once 查找错误,请尝试以下操作:

$filename = realpath('tcpdf_include.php');
var_dump($filename);

当出现问题时,它会输出 bool(false)

要检查是否只是保存 pdf 的问题,请尝试显示文件尝试:

$pdf->Output($pdfSavePathFilename, 'I');

要测试是否是访问权限相关的问题,请尝试:

fopen($pdfSavePathFilename,'w+');

在测试期间禁用 php 警告使用:

error_reporting(0);

【讨论】:

  • 刚刚意识到这总结了一些来自的答案
  • 到目前为止,一个简约的例子有效吗?只有MultiCell并直接输出而不是保存?
猜你喜欢
  • 2014-12-07
  • 2013-12-31
  • 1970-01-01
  • 2014-02-28
  • 2012-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多