PHP生成PDF供下载,文件开头有一个空行

时间:2013-05-07 16:00:37

标签: php pdf

我正在提供PDF文件供PHP下载。

下载的文件出现在文件开头的空行处。

我之所以发现这是因为用户无法在Windows中打开该文件。在Linux中,可以毫无问题地打开PDF。

服务器中的原始PDF文件没有此空行...并且可以由Microsoft用户正常打开。

这是我正在使用的PHP代码:

$f=fopen($filepath,'rb');
#$f=fread($f,filesize($filepath));
if($f){
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Content-Type: '.mime_content_type($filepath));
    header('Content-Length: '.filesize($filepath));
    header('Content-Disposition: attachment; filename="'.$c_file.'"');
    #fpassthru($f);
    while(!feof($f)){
        $buffer=fread($f,2048);
        print $buffer;
    }
    fclose($f);
}else die('Ops!');

以下是下载的PDF文件的开头:

- - -

%PDF-1.4
%Çì¢
7 0 obj
<</Length 8 0 R/Filter /FlateDecode>>
- - -

0 个答案:

没有答案