0

I am working with cakephp. I have generate FDF file using the function from http://koivi.com/fill-pdf-form-fields this URL

It is working fine. Then I generate the PDF file using PDFTK, and have some header to download the file its working fine in Firefox, Chorome and IE but it did not work well in safari browser. In safari it shows the PDF file code. When I use exit(); at the end of commands then safari download the file but it was not not complete.

Normal size of file is 60Kb but with exit() it generate the 48Kb file. So its mean some of the PDF file contents missed out because of exit() command.

If some one can give some hint to solve this problem in safari browser. Thanks in advance.

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="pdf_file_name.pdf"');
header("Content-Type: application/download");
header("Content-Length: " . filesize($pdf_doc));
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
// $pdf_doc is the PDF Form physical path
// $fdf_doc is the FDF file physical path
echo passthru("/usr/local/bin/pdftk $pdf_doc fill_form $fdf_doc output - ");
1
  • I noticed that when the PDF code is displayed in safari and I hit refresh button then it gives the file download option. Mar 20, 2013 at 7:32

2 Answers 2

2

Save the generated file on disk by using the following command of PDFTK

passthru("pdftk $pdf_doc fill_form $fdf_doc output test.pdf");

and then use the same code for already generated PDF as you have. Try the following code after saving the PDF file

header('Content-Disposition: attachment; filename="pdf_file_name.pdf"');
header("Content-Type: application/download");
header('Content-Type:application/pdf');
header("Content-Length: " . filesize("test.pdf"));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
readfile("test.pdf");

Hope this will work in safari as well

0

Try it with header('Content-Type:application/pdf');

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.