Question

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

OTHER TIPS

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);

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');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top