I'm using PDFLib to generate a PDF and download it to the user. My client's hosting company has an older version of PDFLib and I've been just creating the PDF in the buffer and retrieving it with pdf_get_buffer(). My development machine has a newer version and apparently I have to specify the filename, which means I'm creating the file in a directory, which means I can't use pdf_get_buffer().
I know this is simple, but so am I today - can someone remind me of the proper syntax to feed this file to the requester?
Here's my "old" code:
$pdf = pdf_new();
pdf_open_file($pdf);
// PDF DATA HERE
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=cabin_list.pdf");
header("Content-length: " . strlen($data));
echo $data;
The "new" code needs to be something like this (but I need help with the final outputting part):
$pdf = pdf_new();
pdf_open_file($pdf, 'cabin_list.pdf');
// PDF DATA HERE
pdf_close($pdf);
// THIS IS MY BLIND STAB AT OUTPUT, WHICH RESULTS IN A NONWORKING "FILE"
$handle = fopen('cabin_list.php');
$data = fread($handle);
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=cabin_list.pdf");
header("Content-length: " . strlen($data));
echo $data;