- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编辑 2:问题没有解决;我通过切换到使用 ezpdf 而不是 TCPDF 的旧版本文件找到了解决方法,并对其进行了更改以获得所需的打印输出(我不知道为什么整个网站中只有一个页面更改为 TCPDF,但显然它发生了)。我仍然想知道是否有解决此问题的方法,因为 TCPDF 的代码在运行 php 5.2 的服务器上运行正常,但在新服务器上运行不正常。但是,它不再是主要优先事项。
提交 PDF 请求后,我什么也没得到;只是一个空白页。这是从另一台服务器获取的所有代码(我们正在将 php 版本更新到 5.3)并且代码在第一台服务器上运行良好。
Warning: Cannot modify header information - headers already sent (output started at filepath in path/tcpdf.php) TCPDF ERROR: Some data has already been output to browser, can't send PDF file
经过一些调试,我注意到问题是“headers already sent error”,我在更新此站点时遇到过几次。大多数这些错误都可以使用 meta http-equiv
修复,因为它们大多只是页面刷新。但是,TCPDF 使用 header 制作 PDF 文件并强制下载。
如何在不需要 header 的情况下使案例“D”正常工作,如果无法完成,是否可以将案例“I”改为在没有 header 的情况下工作?
我尝试在 $pdf->output()
之前使用 ob_clean()
。我还尝试删除 require_once('./common/tcpdf/config/lang/eng.php')
。这两个都对其他人有固定的问题,我已经广泛研究了这个话题。我不认为它在这种情况下会起作用,因为我知道该网站此时已经开始输出。
我想要的是在下面的代码中使用 header (meta http-equiv?)的替代方法,以防出现“D”(首选)或“I”(可行),这将给我相同的结果(pdf下载或在新选项卡或窗口中打开 pdf)。当然,除非有另一种修复方法。如果没有,我将不得不在不使用 TCPDF 的情况下重新编写页面。
编辑:在原始服务器上,“生成 pdf”会导致页面重新加载,然后在长时间等待(查询数据库时)后,它会强制用户下载。在新服务器上,页面被重新加载,等待查询的时间很长,然后菜单实际上中断了(注销被删除,另一个按钮被移到菜单栏其余部分的下方)并且没有其他任何事情发生。
取自 tcpdf.php 的代码:
case 'I': {
// Send PDF to the standard output
echo "<script>console.log('some log');</script>";
if (ob_get_contents()) {
$this->Error('Some data has already been output, can\'t send PDF file');
}
if (php_sapi_name() != 'cli') {
//We send to a browser
header('Content-Type: application/pdf');
if (headers_sent()) {
$this->Error('Some data has already been output to browser, can\'t send PDF file');
}
header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Length: '.$this->bufferlen);
header('Content-Disposition: inline; filename="'.basename($name).'";');
}
echo $this->getBuffer();
break;
}
case 'D': {
// Download PDF as file
if (ob_get_contents()) {
$this->Error('Some data has already been output, can\'t send PDF file');
}
header('Content-Description: File Transfer');
if (headers_sent()) {
$this->Error('Some data has already been output to browser, can\'t send PDF file');
}
header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
// force download dialog
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream', false);
header('Content-Type: application/download', false);
header('Content-Type: application/pdf', false);
// use the Content-Disposition header to supply a recommended filename
header('Content-Disposition: attachment; filename="'.basename($name).'";');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.$this->bufferlen);
echo $this->getBuffer();
break;
}
最佳答案
我在网上看到很多关于使用 ob_start() 的引用,在文件末尾使用 ob_end_flush()。也许这在某些情况下有效,尽管我真的不明白它会如何。不反对 - 只是说我不明白,而且我没有找到解决问题的办法。
但是,我发现在文件顶部使用 ob_start() 并在输出之前使用 ob_end_clean() 应该可以解决问题。
<?PHP
ob_start();
// All other content
ob_end_clean();
$pdf->Output('MyPDF_File.pdf', 'D');
?>
关于php - 使用 TCPDF 获取 'Headers already sent',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24068529/
我相信 TCPDF 中没有本地方法来创建阴影。我有什么想法可以用其他方法创造这样的效果吗?我首先考虑在每个边缘(对于矩形)旁边创建一个小渐变,但发现没有办法创建具有不同 Alpha channel 的
我已经通读了之前关于该主题的主题,但都是陈旧的、未回答的和/或关于创建自定义字体的更具体的内容。 在 TCPDF 中: $pdf->SetFont('times', '', 10); 我创建的 pdf
在 TCPDF 中有 GetCellHeight()用于测量细胞的高度。 如何测量 TCPDF 中字符串(或字符串块)的长度或宽度? 最佳答案 获取字符串长度的方法是 GetStringWidth()
我正在设置 tcpdf 来为客户即时生成发票,但是当我添加图像时,边框从我的表格中消失了。这是代码: /* if ($status == "Paid") { $pdf->Image("/wp-
我正在使用 TCPDF 生成 pdf。我可以使用 SetMargins($left, $top, $right = -1, $keepmargins = false) 为左、上和右设置边距,但不能为底
我正在使用 TCPDF 生成 pdf。我可以使用 SetMargins($left, $top, $right = -1, $keepmargins = false) 为左、上和右设置边距,但不能为底
从版本 5.9 开始,我还没有找到控制 TCPDF 的 MultiCell 中行距的方法。我也没有找到任何有助于通过使用 Cell 来模拟相同行为的方法,例如返回不适合 Cell 宽度的文本部分的方法
我正在努力了解 header 函数在 tcpdf 中的工作方式。 是否可以将 $pdf->writeHTML 用于标题? http://www.tcpdf.org/examples/example_0
为了创建自定义页眉和页脚,我使用了 TCPDF 的 header()和 footer()函数,但是当我尝试使用函数 $this->image() 在标题中包含图像时, 无法显示图像。文档中的其他图像工
我正在使用 tcpdf 用 PHP 生成 PDF 文件,并且以 .svg 文件的形式嵌入 SVG 图像没有问题,其中包含表示图像的 XML 标记。但是,我希望能够使用该 XML,例如作为 PHP 字符
关于此的主题有很多,但没有一个能解决我的问题。我想做的很简单 - 生成一个条形图,然后将该图嵌入到一个 pdf 文件中,我将使用名为 TCPDF 的库生成该文件。 . 我使用 TCPDF 生成 HTM
第一张图片显示了使用 TCPDF 时的标准 header 布局: 我想做的是右对齐文本,如下所示,但我无法弄清楚如何做到这一点: 请大家给点建议!谢谢。 最佳答案 实现此目的的一种方法是使用 writ
我花了一个多小时研究这个问题,但似乎找不到答案。 我在 TCPDF 中使用 writeHTMLCell 。使用 writeHTMLCell 时,我需要一些文本以适合特定区域。 我见过一个例子here
我正在使用 TCPDF 从 HTML 代码生成 PDF,但无法正确呈现某些 HTML 特殊字符。这是我的准系统代码: require_once('../libraries/tcpdf_6_0_020/
我有以下 svg 文件: http://jsfiddle.net/wptn28c5/ 呈现: 但是,通过使用 tcpdf ($pdf->imageSVG()) 我得到一个呈现的 pdf 文件: 最佳
如何导入现有 pdf文件到新创建的 pdf使用 TCPDF? 所以假设我目前正在做发票部分。一旦用户点击打印发票,我将开始收集数据,然后创建一个 PDF使用 TCPDF .但是,如果可用,我需要“附加
我有以下 tcpdf 代码: SetCreator(PDF_CREATOR); $pdf->SetAuthor('Stimart'); $pdf->SetTitle('test
有谁知道如何使用 PHP TCPDF 导出 PDF/X-1a:2001 PDF 文件图书馆。我研究了很多,但找不到解决方案。有人请指教。解决方案需要在 PHP 中。 最佳答案 我不是 TCPDF 方面
我有一个基于数据生成 PDF 文件的网站。 我在一个免费的虚拟主机上试过了,没问题,但是当我把它上传到我的服务器时,我得到了这个错误: TCPDF 错误:无法打开图像文件:/var/www/html/
我正在使用 TCPDF 来签署 PDF,但是在运行 example 52 时我收到此错误: Warning: openssl_pkcs7_sign() [function.openssl-pkcs7-
我是一名优秀的程序员,十分优秀!