Php open fdf file in browser

I work with cakephp. I need to fill out a PDF form for which I created a fdf file, getting the code http://koivi.com/fill-pdf-form-fields .

The fdf file will generate, but I cannot open the file in the browser. I posted the PDF URL in fdf format and used the following header to show the file. But it shows the original contents of the fdf file.

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

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

Here is the code I get 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 
+4
source share
3 answers

First try exiting () after the echo file so CakePHP does not add the result to the response.

A cleaner way to do this is to use CakeResponse to transfer the file through:

 return $this->response->file($fdf_doc); 
+2
source

The reason is because the browser cannot recognize the type of content.
Therefore, he believes that this is plain text and does not know that it is a PDF. Invalid content type:

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

Try the following:

 header('Content-type: application/pdf'); 
+1
source

All Articles