phpfirefoxpdfpassthru

Getting html into the pdf file when output with passthru


I get an error when trying to display my pdf in a popup window. This may be caused when I do a passthru. My browser is Firefox(14.0.1).

I generate a pdf on the serverside that I want to show in a browser popup. I create the pdf and set a header( header('Content-type: application/pdf'); ) and do a passthru('cat my_pdf_file').

What I end up with is my index.php file's html in the beginning of the pdf and in the end of the pdf. It's like my PDF is embedded in the index file and I download the whole thing(index with the pdf). I only want to show the content of the pdf.

This happens during the passthru and I can watch it correctly when FTP downloading the file to my desktop and open from there.

I detected it when opening the pdf with notepad++ and saw the coded content.

Any suggestions how to solve this to only get the pdf ?

Best regards,

Gabriel Paulsson


Solution

  • The header function should be called before any output is sent to the browser. Furthermore, there shouldn't be any html tag the page you are using to download the pdf: you should output just the pdf data.