Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPDF ERROR: Some data has already been output, can't send PDF file

Tags:

php

tcpdf

I keep receiving this error when trying to add my own array into the code. Here is my array;

$array = array();  while (odbc_fetch_row($rs)) {     $array[] = odbc_result($rs,'Product Name'); }   $test = print_r($array); 

The original code is here. I'm using an example page to try it because I know the example page works fine.

http://www.tcpdf.org/examples/example_001.phps

This code is before the $html variable and when it is set I just add the $test variable into the $html variable. The odbc connection works fine and the example works fine before I add any code but when I run the script I get this error;

Array ( [0] => Test1 [1] => Test2 ) TCPDF ERROR: Some data has already been output, can't send PDF file 

And there is also more than 2 items in the Array. Any ideas?

like image 209
Alex Avatar asked Apr 15 '13 08:04

Alex


People also ask

How to fix TCPDF error Some data has already been output can t send PDF file?

Solution. The first and most common solution, is to search on your code what is the line or code that is generating some output before TCPDF and remove it (mentioned methods as print_r, var_dump, echo etc).

What does TCPDF error mean?

You may see this error when generating your PDF catalog: TCPDF ERROR: Could not include font definition file: arialmt. The error means that the font (in this example arialmt) is missing in the modules configuration files. You will therefore need to add the font in the corresponding folder.


2 Answers

Add the function ob_end_clean(); before call the Output function. It worked for me within a custom Wordpress function!

ob_end_clean(); $pdf->Output($pdf_name, 'I'); 
like image 158
Fab Avatar answered Oct 11 '22 13:10

Fab


Just use ob_start(); at the top of the page.

like image 36
vishal jaura Avatar answered Oct 11 '22 15:10

vishal jaura