PHP: Adobe Reader 无法打开使用 fpdf 创建的 PDF 文件
PHP: Adobe Reader can't open PDF files created with fpdf
我已经使用 fpdf 生成了 pdf 文件,但出现错误。
Adobe reader 无法打开 'invoice.pdf',因为它不是受支持的文件类型或文件已损坏。任何帮助将不胜感激!
<?php
$f_name=$_POST['first-name'];
if(isset($_POST['submit']))
{
$f_name=$_POST['name'];
$l_name=$_POST['last-name'];
$email=$_POST['email'];
require("fpdf/fpdf.php");
$fpdf=new FPDF();
$fpdf->AddPage();
$fpdf->setFont("Arial","B",16);
$fpdf->Cell(0,10,"Invoice",1,1,"C");
$fpdf->Cell(95,10,"Name:",1,0,"C");
$fpdf->Cell(95,10,$f_name,1,1,"C");
$fpdf->Cell(95,10,"Last Name:",1,0,"C");
$fpdf->Cell(95,10,$l_name,1,1,"C");
$fpdf->Cell(95,10,"Email:",1,0,"C");
$fpdf->Cell(95,10,$email,1,1,"C");
$file_location = $_SERVER['DOCUMENT_ROOT']."/invoice/up_pdfs/".$f_name.".pdf";
file_put_contents($file_location,$fpdf);
ob_clean();
$fpdf->output();
header("Location: index.php");
}
?>
使用 $fpdf->Output($file_location,'F');
并删除 file_put_contents($file_location,$fpdf);
if(isset($_POST['submit']))
{
$f_name=$_POST['name'];
$l_name=$_POST['last-name'];
$email=$_POST['email'];
require("fpdf/fpdf.php");
$fpdf=new FPDF();
$fpdf->AddPage();
$fpdf->setFont("Arial","B",16);
$fpdf->Cell(0,10,"Invoice",1,1,"C");
$fpdf->Cell(95,10,"Name:",1,0,"C");
$fpdf->Cell(95,10,$f_name,1,1,"C");
$fpdf->Cell(95,10,"Last Name:",1,0,"C");
$fpdf->Cell(95,10,$l_name,1,1,"C");
$fpdf->Cell(95,10,"Email:",1,0,"C");
$fpdf->Cell(95,10,$email,1,1,"C");
$file_location = $_SERVER['DOCUMENT_ROOT']."/invoice/up_pdfs/".$f_name.".pdf";
ob_clean();
$fpdf->Output($file_location,'F');
header("Location: index.php");
}
?>
我已经使用 fpdf 生成了 pdf 文件,但出现错误。 Adobe reader 无法打开 'invoice.pdf',因为它不是受支持的文件类型或文件已损坏。任何帮助将不胜感激!
<?php
$f_name=$_POST['first-name'];
if(isset($_POST['submit']))
{
$f_name=$_POST['name'];
$l_name=$_POST['last-name'];
$email=$_POST['email'];
require("fpdf/fpdf.php");
$fpdf=new FPDF();
$fpdf->AddPage();
$fpdf->setFont("Arial","B",16);
$fpdf->Cell(0,10,"Invoice",1,1,"C");
$fpdf->Cell(95,10,"Name:",1,0,"C");
$fpdf->Cell(95,10,$f_name,1,1,"C");
$fpdf->Cell(95,10,"Last Name:",1,0,"C");
$fpdf->Cell(95,10,$l_name,1,1,"C");
$fpdf->Cell(95,10,"Email:",1,0,"C");
$fpdf->Cell(95,10,$email,1,1,"C");
$file_location = $_SERVER['DOCUMENT_ROOT']."/invoice/up_pdfs/".$f_name.".pdf";
file_put_contents($file_location,$fpdf);
ob_clean();
$fpdf->output();
header("Location: index.php");
}
?>
使用 $fpdf->Output($file_location,'F');
并删除 file_put_contents($file_location,$fpdf);
if(isset($_POST['submit']))
{
$f_name=$_POST['name'];
$l_name=$_POST['last-name'];
$email=$_POST['email'];
require("fpdf/fpdf.php");
$fpdf=new FPDF();
$fpdf->AddPage();
$fpdf->setFont("Arial","B",16);
$fpdf->Cell(0,10,"Invoice",1,1,"C");
$fpdf->Cell(95,10,"Name:",1,0,"C");
$fpdf->Cell(95,10,$f_name,1,1,"C");
$fpdf->Cell(95,10,"Last Name:",1,0,"C");
$fpdf->Cell(95,10,$l_name,1,1,"C");
$fpdf->Cell(95,10,"Email:",1,0,"C");
$fpdf->Cell(95,10,$email,1,1,"C");
$file_location = $_SERVER['DOCUMENT_ROOT']."/invoice/up_pdfs/".$f_name.".pdf";
ob_clean();
$fpdf->Output($file_location,'F');
header("Location: index.php");
}
?>