TCPDF &mPDF错误:部分数据已经输出到浏览器,无法发送PDF文件 [英] TCPDF & mPDF error: Some data has already been output to browser, can't send PDF file

查看:25
本文介绍了TCPDF &mPDF错误:部分数据已经输出到浏览器,无法发送PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

TCPD &mPDF错误:部分数据已经输出到浏览器,无法发送PDF文件我放弃了尝试使用 TCPDF 修复错误并安装 mPDF 只是为了在尝试将文档呈现到浏览器时出现相同的错误.我可以很好地保存文档并在检索时将其显示在浏览器中.

TCPDF & mPDF error: Some data has already been output to browser, can't send PDF file I gave up on trying to fix the error with TCPDF and installed mPDF only to get the same error when attempting to render the document to the browser. I can save the document just fine and have it displayed in the browser upon retrieval.

此外,此错误仅在从我的开发服务器切换到我的主机服务器后才出现.在 DEV 服务器上运行良好(DEV 服务器 = WAMPSERVER,PROD 服务器 = Hostgator Linux).

Additionally, this error only presented itself after switching from my dev server to my host server. Works fine on DEV server (DEV server = WAMPSERVER, PROD server = Hostgator Linux).

疑难解答:

我在互联网上阅读了许多关于此问题的其他讨论,但我找不到与空白相关的问题.我已将请求浓缩为以下内容:

I've read the many volumes of other discussions around the internet regarding this problem and I can find no white space related issue. I have condensed the request to the following:

<?php
ob_start(); 
$html = "Hello World";
include("../mpdf.php");
$mpdf=new mPDF(); 
$mpdf->WriteHTML($html);
$mpdf->Output();
ob_end_clean();
?>

在 writeHtml 之前使用 ob_clean() 方法尝试了与 TCPDF 相同的概念.在所有情况下都出现相同的错误(我可以向所有人保证这不是与空格相关的问题 - 我什至以十六进制查看文件以确保编辑器没有插入奇怪的字符).

Tried the same concept with TCPDF using ob_clean() method before writeHtml. Same error in all cases (I can assure everyone this is no white space related issue - I even viewed the file in hex to make sure there were no odd characters being inserted by the editor).

可能的线索:

当我将整个 mPDF 库以及类和文件夹移动到 public_html 文件夹而不是从我的应用程序文件夹(一个 symfony 项目)内部时,我终于能够了解发生了什么.在这种情况下,当我将浏览器指向示例页面时,它呈现得很好,根本没有错误(顺便说一句,它是超快的).所以,我知道它有效,并且我知道没有与空白相关的问题或任何其他相关问题,关于代码或安装(在 mPDF/TCPD 方面).这让我相信 symfony 正在插入某种标题(我尝试使用: clearHttpHeaders() 删除),或者有一个 PHP INI 或 CONFIG 设置我在 PROD 服务器上的某个地方丢失了.

I was finally able to get a clue as to what's going on when I moved the entire mPDF library and classes and folders to the public_html folder, rather than from inside my application folder (a symfony project). Under this scenario, when I pointed my browser to the example pages, it rendered just fine with no errors at all (and it was super fast btw). So, I know it works, and I know there is no white-space related issue, or any other related issue, regarding the code or installation (on the mPDF/TCPDF side of things). Which leads me to believe either symfony is inserting headers of some sort (which I tried removing using: clearHttpHeaders() ), or there is a PHP INI or CONFIG setting I am missing somewhere on the PROD server.

有人知道这里发生了什么吗?

Does anyone have ANY idea of what's going on here??

更新:流转储:

Request URL:http://www.example.com/mpdf
Request Method:GET
Status Code:200 OK

Request Headers
GET /mpdf HTTP/1.1
Host: www.example.com
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Cookie: __utma=44708724.1463191694.1383759419.1383759419.1383765151.2; __utmz=44708724.1383759419.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=9c7c802200b9d8eefe718447755add5f; __utma=1.813547483.1383767260.1385127878.1385130071.38; __utmb=1.7.10.1385130071; __utmc=1; __utmz=1.1383767260.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)

Response Headers
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Type:text/html
Date:Fri, 22 Nov 2013 14:59:52 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=75
Pragma:no-cache
Server:Apache
Transfer-Encoding:chunked

什么都没有想到……还有其他想法吗?

Nothing is jumping out at me... any other thoughts?

推荐答案

很可能是 BOM 标记,使用您的 IDE 删除它,其他修补程序可以是:

Most probably it's BOM marker, use your IDE to remove it, other hot fix can be:

<?php

$html = "Hello World";
include("../mpdf.php");

ob_clean(); // cleaning the buffer before Output()

$mpdf=new mPDF(); 
$mpdf->WriteHTML($html);
$mpdf->Output();

?>

这篇关于TCPDF &amp;mPDF错误:部分数据已经输出到浏览器,无法发送PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆