Jump to content

How to generate PDF file so it can be downloaded?


exphp

Recommended Posts

Hello everyone.

I have a problem to generate PDF file using FPDF and PHP.

I'll not ask you how to create the pdf file, but I need help to generate a link to PDF file so it can be downloaded automatically.

 

I mean like this:

I already created a php page that create PDF file, name: report.php. I must open the report.php page to see the pdf file then click "Save" or press Ctrl + S to save the PDF file. But, now I need to generate report.php become report.pdf automatically so the pdf file can be downloaded automatically.

 

For example, if I click a button "Generate Link", so the value will be:

echo "<a href='report.pdf' title='download pdf file'>Download PDF File</a>";

not

echo "<a href='report.php' title='download pdf file'>Download PDF File</a>";

 

Do you have any ideas or solution for this case?

I really appreciate it.

Thanks.

Except in IE, and hopefully just the older versions, the filename you link to doesn't matter. Along with the header() that says it's a PDF file, include a

header("Content-Disposition: attachment; filename=report.pdf");

That will make the browser prompt to download and will use the filename "report.pdf" by default.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.