4

I am working with cakephp. I need to fill up a PDF form for which I have generated the fdf file by getting the code from http://koivi.com/fill-pdf-form-fields.

the fdf file is going to generate well but I am unable to open the file in browser. I have put the live PDF form URL in fdf file and use the following header to show the file. But shows the original content of fdf file.

header("Content-type: application/vnd.fdf");
echo file_get_contents($fdf_doc);

Please someone help to show the pdf file in browser with the data in fdf file.

Here is the code which I am getting against the above two lines of code

%FDF-1.2
%âãÏÓ
1 0 obj
<< 
/FDF << /Fields [ <</T(First_Name_dyoZTsSYj7AaZZORUqwHRg)/V(m)>><</T(Last_Name_wtE2EKuY4zimhkLHVtbImQ)/V(Jhon)>><</T(Address_iw9xRob*WcfI6Yx1VvF6lA)/V(Steve)>><</T(City_hdYMQhyO73*HEfQYtnWpyg)/V(lahore)>><</T(ZIP_Code_lSOicM9dFoK1WNlOn*BMdg)/V(232323)>><</T(Phone_l3ZSQxhOYwSFuzdOta-WNw)/V(98989898)>><</T(Arrival_Date_Jy6nv5X38KS1lyDYw-*uAQ)/V(01/30/2010)>><</T(Departure_Date_uFmnQc6dxs4jn7s*g32RAA)/V(02/03/2010)>><</T(Number_of_guest_0iHYhUsjJEAoMGsWL9koXA)/V(5)>><</T(Flight_Number_zY9NGizqNvliyJFB0IEmxA)/V(PK-506)>><</T(Time_N18PoY40LFC6LCUUBXb4JA)/V(16:08)>><</T(ADDITIONAL_INFO_0MGHwGHCfZmli5zV6WpKPA)/V(this is for testing for hotel registration)>><</T(file_name)/V(AccommodationRegistration1.pdf)>>] 
/F (http://example.com/pdf_files/AccommodationRegistration1.pdf) /ID [ <2deb20b6495e049130fbca026c4fd1d3>
] >> 
>> 
endobj
trailer
<<
/Root 1 0 R 

>>
%%EOF
Jeffrey Nicholson Carré
  • 2,950
  • 1
  • 26
  • 44
nbhatti2001
  • 353
  • 2
  • 7
  • 33
  • I guess your question is already answered here: http://stackoverflow.com/a/1390496/1249581. – VisioN Mar 08 '13 at 07:46
  • 1
    pdftk is third party tool, which need to install on server. If we can do it without pdftk that will be better. – nbhatti2001 Mar 08 '13 at 07:49
  • Attention from http://php.net/manual/en/function.file-get-contents.php about `file_get_contents` Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. – Amir Mar 11 '13 at 08:14
  • Why are you trying to open the FDF file in the browser? You need to execute some code or program that merges the FDF file and a fillable PDF file, such as the suggested `pdftk`. The same site has a tutorial: http://koivi.com/fill-pdf-form-fields-filled . Is your intention to download the user's FDF data and manually merge the data with the PDF? – Moshe Katz Mar 14 '13 at 19:19
  • 1
    pdftk is not available on shared hosting, and we need automate process to do it. – nbhatti2001 Mar 14 '13 at 20:02
  • http://stackoverflow.com/a/11531682/1427338 – Jeffrey Nicholson Carré Mar 15 '13 at 05:02
  • Thanks to all for participating to find the solution – nbhatti2001 Mar 15 '13 at 05:46

3 Answers3

4

You should generate a pdf out of the fdf

helpful articles :

  1. FDF
  2. Installing PDFTK on a shared web server
  3. Adding pdftk to 1and1 shared hosting
Community
  • 1
  • 1
Jeffrey Nicholson Carré
  • 2,950
  • 1
  • 26
  • 44
  • I have create PDF file using PDFTK from FDF file. I did not find any direct solution to show the FDF file in browser. Although I have find come clue while searching on net to show FDF file in browser but it did not work. Thanks to all for participating to find the solution – nbhatti2001 Mar 15 '13 at 05:46
2

First try to exit() after echoing the file to prevent CakePHP from adding output to the response.

A cleaner way to do this is using CakeResponse for passing the file through:

return $this->response->file($fdf_doc);
nanoman
  • 1,069
  • 12
  • 27
1

The reason is that the browser is unable to recognize the content type.
So it thinks it is a plain text and does not know that this is PDF.
You have invalid content type:

header("Content-type: application/vnd.fdf");

Try this one:

header('Content-type: application/pdf');
Bogdan Burym
  • 5,482
  • 2
  • 27
  • 46