DOMPDF: Unable to stream pdf: headers already sent

后端 未结 10 2135
夕颜
夕颜 2020-12-18 06:45

This question has been raised hundred of times in various fora; some have been solved, some not. I checked plenty of resources, but my issue could not be resolved. I am gene

相关标签:
10条回答
  • 2020-12-18 07:29

    Most probably there's a whitespace or new line somewhere in your code causing this. Here's a simple way to debug it:

    1. echo something at the very end of your script (above the stream() call), for example echo "end!";exit;
    2. Click to "view source" of your page, which makes spaces easier to see
    3. If your "end!" string does not appear at the very start of your script, then somewhere there's a character printed
    4. Move the "echo end!" line further up to your code, until you locate where the space was inserted

    Another possibility is that you are using a language string somewhere that introduces an unprintable character. If your application is multilingual, make sure you're testing using english

    0 讨论(0)
  • 2020-12-18 07:31

    Be sure your editor does not add a Unicode Bom description - save code to file by Notepad, or (if you work in Dreamweaver) remove check by Asign Unicode Signature (BOM) or something. ;)

    0 讨论(0)
  • 2020-12-18 07:34

    I tried to echo out, but no white spaces or line breaks were found. At the end, I redirected the php to another page instead of PHP_SELF and the problem vanished. I did not alter any code. Looks like presence of html tags after the php ended was the offending factor.

    0 讨论(0)
  • 2020-12-18 07:39

    I came across this issue. You want to check all the variables you are using. One or even more than one variable you are passing comes empty and is messing the render.

    Start gradually, by getting rid of all the php and try to generate the pdf, then if it works for you add code block by block.

    This will help you identify where the problem is.

    0 讨论(0)
提交回复
热议问题