输出('file.pdf','D')下载文件,但不'显示在浏览器中


fpdf Output('file.pdf','D') download the file but doesn't show it in the browser

我在php中使用FPDF类在我的网页中创建pdf文件,但它下载pdf但不显示在浏览器上或创建一个垃圾。

这是我的代码

<?php
require('fpdf/fpdf.php'); 
$pdf =new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('file.pdf','D');
?>

这段代码下载了PDF文件,但没有在页面中显示PDF文件如果我改变

的最后一行
$pdf->Output('file.pdf','D'); to $pdf->Output('file.pdf','I');

它输出这个

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T04�30PISp  �Z*�[����(hx����+����(j*�d��7W endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 5 0 R >> /XObject << >> >> endobj 6 0 obj << /Producer (FPDF 1.7) /CreationDate (D:20150920120751) >> endobj 7 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 8 0000000000 65535 f 0000000228 00000 n 0000000416 00000 n 0000000009 00000 n 0000000087 00000 n 0000000315 00000 n 0000000520 00000 n 0000000595 00000 n trailer << /Size 8 /Root 7 0 R /Info 6 0 R >> startxref 644 %%EOF

任何帮助

或者你能给我推荐其他方法在php中创建PDF文件

参见http://www.fpdf.org/en/doc/output.htm

string Output([string dest [, string name [, boolean isUTF8]]]) 

$pdf->Output('I','file.pdf');