Save a generated PDF file using php

Last updated 2 years, 11 months ago | 559 views 75     5

Tags:- PHP

PHP | Download pdf file

To download a pdf file in PHP, we need to use the header() function. In the header() function, we need to pass "Content-Disposition" which is used to supply a recommended filename and force the browser to display the save dialog box

<?php
header("Content-type:application/pdf");

// It will be called downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");

// The PDF source is in original.pdf
readfile("original.pdf");
?>

<html>
<body>

...
…

Note: There is a bug in Microsoft IE 5.5 that prevents this from working. The bug can be resolved by upgrading to Service Pack 2 or later.