简体   繁体   English

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

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

I am using FPDF class in php to create pdf file in my webpage but it download the pdf but doesn't show it on the browser or create a garbage.我在 php 中使用 FPDF 类在我的网页中创建 pdf 文件,但它下载了 pdf 但没有在浏览器上显示它或创建垃圾。

here is my code这是我的代码

<?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');
?>

this code download the pdf file but doesn't show the pdf file in the page if i change the last line from此代码下载pdf文件,但如果我更改最后一行,则不会在页面中显示pdf文件

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

it output this它输出这个

%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

any help任何帮助

or can you recommend me other method to create pdf file in php或者你能推荐我其他方法在 php 中创建 pdf 文件吗

see http://www.fpdf.org/en/doc/output.htmhttp://www.fpdf.org/en/doc/output.htm

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

so所以

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

should do it.应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM