I'm generating PDF using tcpdf library in WordPress admin side. but getting the following error. TCPDF ERROR: Some data has already been output to browser, can't send PDF file

It has header_sent() is true means it has set its headers already and not modifying the pdf headers by tcpdf. any ideas ?

  • Have you tried putting your code in earlier during the load process? admin_init or earlier? – Tom J Nowell Nov 24 '11 at 12:45
  • No, how I can do that ? I'm outputting the code at top of custom admin page. – Muhammad Adnan Nov 29 '11 at 18:58
  • put it in a function then attach that function to a hook – Tom J Nowell Nov 29 '11 at 21:29
  • in this hook admin_init ? – Muhammad Adnan Nov 30 '11 at 6:08
  • I tried this <br /> ** function generate_pdf_test_with_admin(){ echo 'test'; } add_action( 'admin_init', 'generate_pdf_test_with_admin' );** <br /> but it doesn't echo anything on page – Muhammad Adnan Nov 30 '11 at 6:51

I would recommend doing this:

On the page where you are currently trying to output the PDF to the browser, save the PDF to a file on your server instead. Then, add a link to the file on your admin page.

This way the download of the PDF is a separate browser GET request and there will be no problem with headers.

If you are trying to output HTML and a PDF on the same admin page then it will never work, no matter how early in the page-render you put the PDF output.

Not the answer you're looking for? Browse other questions tagged or ask your own question.