Reputation: 4007
I use FPDF to generate some PDF from a PHP. It worked great for small exemple but now i got a problem with it : it return some data which i saw in the console but no file !
ouput look likes - it's the PDF no ?
%PDF-1.4
0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>
......
<<
/Size 15
/Root 14 0 R
/Info 13 0 R
>>
startxref
22291
%%EOF
And my php is pretty long, here is a pastebin of it http://pastebin.com/ri5uAeie
My php looks correct, really weird no ?
I pass my param throw the URL and with a $_GET and it works well :) Thanks for your help guys !
Upvotes: 0
Views: 2935
Reputation: 146340
You've probably added a blank line somewhere, possibly at inc/DataLib.php
.
Update #1:
According to your answers, there's two suspicious points:
The Content-Type
should be application/pdf
. In theory, the PDF::Output() method adds it for you (unless php_sapi_name()
returns cli
, which should not be possible in web environment).
Getting a blank page in a desktop PDF reader (rather than an error) suggests that the document is damaged in a way that the reader cannot even detect it... or that the document is actually blank.
No idea about #1 (firewall? proxy? antivirus?) but you could at least inspect the PDF source in search of PHP error messages or something that does not belong there.
Update #2:
I think I finally understood what your problem is. You cannot use JavaScript to retrieve a PDF file though AJAX. All JavaScript can do is:
I suspect your PDF generator is just fine if you call it directly from the location bar.
Upvotes: 3
Reputation: 62359
That's how calling FPDF::Output()
with no arguments work. It just sets appropriate headers and sends PDF as text to browser. If you want the file to be downloaded, you need to provide Output()
with filename and set second argument to 'D'
Upvotes: 0