首页 > 解决方案 > 将 PDF 文件另存为 PDF 而不是 PHP

问题描述

我正在使用 FPDF 创建 pdf 文件。但它显示扩展为 php 而不是 pdf。当我在手机中下载文件时,它会显示 .php 文件。现在如何将 php 扩展名转换为 pdf

这里 index.php 文件

 <a href="pdf.php">Click Here</a>

这里 pdf.php 文件

 <?php
 require ("fpdf/fpdf.php");
 $name = "Amit Samadder";
 $pdf = new FPDF('p','mm','A4');
 $pdf->AddPage();
 $pdf->SetFont("Arial","B","20");
 $pdf->Cell(100,10, $name, 1,0, "C");
 $pdf->Output();
?>

标签: phpfpdf

解决方案


看看http://fpdf.org/en/doc/output.htm

您需要更改此行:

$pdf->Output();

至:

$pdf->Output('D', 'myfile.pdf');

推荐阅读