Reputation: 437
I have php code that saves the data in a form to pdf. However right now, its simply opening the data in pdf rather than prompting me to save it as pdf. How can I do that? My code is as follows:
<?php
if(!empty($_POST['submit']))
{
$f_name=$_POST['first_name'];
$l_name=$_POST['last_name'];
$gender=$_POST['gender'];
$dob=$_POST['dob'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
require("fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial","B",16);
$pdf->Cell(10,10,"welcome {$f_name}",1,0);
$pdf->Cell(50,10,"Name :",1,0);
$pdf->Cell(50,10,"$l_name",1,0);
$pdf->Cell(50,10,"gender :",1,0);
$pdf->Cell(50,10,"$gender",1,1);
$pdf->Cell(50,10,"Mobile :",1,0);
$pdf->Cell(50,10,"$mobile",1,1);
$pdf->Cell(50,10,"Email :",1,0);
$pdf->Cell(50,10,"$email",1,1);
$pdf->Output("D", "filename.pdf");
}
?>
Upvotes: 0
Views: 864
Reputation: 4218
FPDF's output() method takes two parameters which determine how to output the document. In the version of FPDF I have, they are the opposite way around to the documentation, so you might want to try both:
$pdf->Output("filename.pdf", "D");
(which worked for me) and:
$pdf->Output("D", "filename.pdf");
(which is as per the documentation).
"D" means "send to the browser and force a file download with the name given by name" whereas the default is "I" which means "send the file inline to the browser. The PDF viewer is used if available."
Upvotes: 1