Reputation: 41
I am generating PDF file by using FPDF library with PHP. PDF file getting generated and showing in browser perfectly.
However instead of it showing in browser I want forcefully save option instead of showing it.
Upvotes: 1
Views: 2442
Reputation: 1
Yeah, you can do this with .htaccess
as well.
Just add the following line:
AddType application/octet-stream .pdf
Upvotes: 0
Reputation: 4063
FPDF has a download function build in, use the D
argument:
// At the end of your PDF generation code:
$pdf->Output('file.pdf', 'D');
Upvotes: 1
Reputation: 6021
To do this, you need to send the appropriate content header:
<?php
header('Content-Type: application/pdf');
header('Content-disposition: attachment;filename=MyFile.pdf');
readfile('MyFile.pdf');
To implement this, simply cause the user's browser to open a page with the above headers, where MyFile.pdf refers to your pdf file's location (you can use cookies, sessions, form submissions, or whatever to figure out that file location). In this example I left off the closing ?>
tag; this may or may not be neccessary.
Upvotes: 0