简体   繁体   中英

FPDF return me text instead of PDF File

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 ?

UPDATE

I pass my param throw the URL and with a $_GET and it works well :) Thanks for your help guys !

You've probably added a blank line somewhere, possibly at inc/DataLib.php .

Update #1:

According to your answers, there's two suspicious points:

  1. 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).

  2. 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:

  1. Manipulate the page's DOM (and PDF is not HTML).
  2. Replace the complete DOM page with something else (and there's no way to tell the browser what content-type it is).

I suspect your PDF generator is just fine if you call it directly from the location bar.

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM