I have a pdf file called newdesign.pdf, which I am serving up with the code below. It's fine on my own machine, but when I go on the server, the problem is that instead of opening a PDF file, the browser just shows up all the garbled PDF source text.
This is my code:
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Length: ' . filesize("newdesign.pdf"));
// to open in browser
header('Content-Disposition: inline; filename=' . basename("newdesign.pdf"));
readfile("newdesign.pdf");
And this is the beginning of the output:
Warning: Cannot modify header information - headers already sent by (output started at /home/zeejfl5/public_html/ui_test/savedesign.php:8) in /home/zeejfl5/public_html/ui_test/savedesign.php on line 71
%PDF-1.4 1 0 obj << /Title (��) /Creator (��) /Producer (��wkhtmltopdf) /CreationDate (D:20120903012618-07'00') >> endobj 3 0 obj << /Type /ExtGState /SA true /SM 0.02 /ca 1.0 /CA 1.0 /AIS false /SMask /None>> endobj 4 0 obj [/Pattern /DeviceRGB] endobj
8 0 obj << /Type /Catalog /Pages 2 0 R >> endobj 5 0 obj << /Type /Page /Parent 2 0 R /Contents 9 0 R /Resources 11 0 R /Annots 12 0 R /MediaBox [0 0 454 227] >>
endobj 11 0 obj << /ColorSpace << /PCSp 4 0 R /CSp /DeviceRGB /CSpg /DeviceGray >> /ExtGState << /GSa 3 0 R >> /Pattern << >> /Font << /F6 6 0 R /F7 7 0 R >> /XObject << >> >> endobj 12 0 obj [ ] endobj 9 0 obj << /Length 10 0 R /Filter /FlateDecode
>> stream x��[M��0��W̹`E}YPzhh=B=�J�۲$K�=��wl'Y9�d74�F��$��4�����������t��v:J*���[5,Vb k13�m۵�
My PDF file itself is fine, if you open using Adobe Reader. But how to open it in the browser for the user's viewing? I don't think there's anything wrong in the code because it works fine on my local machine. It only acts up when I upload the script to the server.