TCPDF error in production , but not in developer mode

I tried to generate PDF using TCPDF , when in developer mode, I have no trouble and result shown, but when after I upload via ftp to hosting, the error occured
[h=1][SIZE=14px]TCPDF ERROR: Some data has already been output, can’t send PDF file[/SIZE][/h] I tried several trick and nothing could fix that, strange because in developer mode no error happens.

This is my code

Event OnScriptInit

[strbrg]="";
[qtybrg]="";
[pricebrg]="";
[totprice]="";
[namacust]="";
[alamatcust]="";
[kotacust]="";
[namasales]="";
[tglinvoice]="";
[terbilang]="";

Event OnRecord

sc_include(convertnum.php);

$sqlstr="select fnamabrg, fqty,fharga from tbjualdet inner join tbbarang on tbjualdet.fidbarang=tbbarang.fidbarang where fnojual='". [globjual] ."'";

//sc_alert([globjual]);
sc_lookup(my_data, $sqlstr);

//$j=0;
if (!empty ({my_data})) {
    $datasetCount = count({my_data}); // returns count of array items of any array

    for($j=0; $j < $datasetCount; $j++)
    {
        //nama brg
        //[namabrg][$i]={my_data[$j][0]};
        [strbrg].={my_data[$j][0]};
        [strbrg].=".";

        //qty brg
        [qtybrg].={my_data[$j][1]};
        [qtybrg].=".";

        //harga barang
        [pricebrg].={my_data[$j][2]};
        [pricebrg].=".";

        //tot price
        [totprice].={my_data[$j][2]} * {my_data[$j][1]}; 
        [totprice].=".";

        [terbilang]=[terbilang]+({my_data[$j][2]} * {my_data[$j][1]});

}
    [terbilang]=terbilang([terbilang]);

}

And this code is in Layout PDF Code

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('I-CON');
$pdf->SetTitle('Invoice Kutus');
$pdf->SetSubject('Invoice'. [globjual]);
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
//$pdf->AddPage('P','A4'); //A4 Portrait
//$pdf->AddPage('L','A4'); //A4 Landscape

ob_start();

$path="";
//$fontname = $pdf->AddFont('/font/ARIALN.TTF', 'TrueTypeUnicode', '', 32);
sc_pdf_add_font ('ARIALN', '', 'arialn.php');

//echo $tbl;
$pdf->SetXY(25, 5);
$path='http://' . $_SERVER['SERVER_NAME'] . '/_lib/img/invoicepic2.jpg';
$pdf->Image($path, 5, 3, 15, 13, 'JPG', '', '', false, 150, '', false, false, 0, false, false, false);
$pdf->SetFont('Arial','B',10);
$pdf->Write(0, 'I N V O I C E', '', 0, 'L', true, 0, false, false, 0);
//$pdf->Write(0, $path, '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(5, 18);
$pdf->SetFont('helvetica', '', 8);
$pdf->Write(0, 'Mobile: 081233511650 ', '', 0, 'L', true, 0, false, false, 0);
sc_pdf_set_font ('ARIALN', '', 8);
$pdf->SetXY(5, 24);
$pdf->Write(0, 'No. Invoice : ', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(20, 24);
$pdf->Write(0, [globjual], '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(5, 28);
$pdf->Write(0, 'Tgl. Invoice : ', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(20, 28);
$pdf->Write(0, [tglinvoice], '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(5, 32);
$pdf->Write(0, 'Pembayaran : ', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(20, 32);

$pdf->SetXY(5, 36);
$pdf->Write(0, 'Salesman : ', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(20, 36);
$pdf->Write(0, [namasales], '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(5, 40);
$pdf->Write(0, 'Kepada : ', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(15, 40);
$pdf->Write(0, [namacust], '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(15, 44);
$pdf->Write(0, [alamatcust], '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(15, 48);
$pdf->Write(0, [kotacust], '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(5, 52);
$pdf->Write(0, 'No.Seri : ', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(3, 58);
$pdf->Write(0, 'Nama Barang               Qty      Harga       Total', '', 0, 'L', true, 0, false, false, 0);

sc_pdf_set_font ('ARIALN', '', 7);
$ContPosY=62;
//nama barang
$name_prod = [strbrg];
$arr_name_prod = explode(".",$name_prod);
foreach($arr_name_prod as $typeName){
    $pdf->SetXY(2, $ContPosY);
    $pdf->Write(0, $typeName, '', 0, 'L', true, 0, false, false, 0);    
    $ContPosY+=4;
}

//qty barang
$ContPosY=62;
$qty_prod = [qtybrg];
$arr_qty_prod = explode(".",$qty_prod);
foreach($arr_qty_prod as $typeName){
    $pdf->SetXY(20, $ContPosY);
    //$pdf->Write(0, $typeName, '', 0, 'L', true, 0, false, false, 0);    
    $pdf->MultiCell(13, '', number_format($typeName, 0, '.', ','), 0, 'R', 0, 1, '','', true);
    $ContPosY+=4;
}

//price brg
$ContPosY=62;
$price_prod = [pricebrg];
$arr_price_prod = explode(".",$price_prod);
foreach($arr_price_prod as $typeName){
    $pdf->SetXY(32, $ContPosY);
    $pdf->MultiCell(14, '', number_format($typeName, 0, '.', ','), 0, 'R', 0, 1, '', '', true);
    //$pdf->Write(0, number_format($typeName, 2, '.', ''), '', 0, 'R', true, 0, false, false, 0);
    $ContPosY+=4;
}

//harga*qty
$ContPosY=62;
$totalprice=0;
$tot_prod = [totprice];
$arr_tot_prod = explode(".",$tot_prod);
foreach($arr_tot_prod as $typeName){
    $pdf->SetXY(38, $ContPosY);
    //$pdf->Write(0, $typeName, '', 0, 'L', true, 0, false, false, 0);
    $pdf->MultiCell(20, '', number_format($typeName, 0, '.', ','), 0, 'R', 0, 1, '', '', true);
    $totalprice=$totalprice+$typeName;
    $ContPosY+=4;
}

$ContPosY-=2;
$style = array('width' => 0.2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 10, 'color' => array(0, 0, 0));
$pdf->Line(2, $ContPosY, 70, $ContPosY, $style);
$ContPosY+=1;
$pdf->SetXY(1, $ContPosY);
$pdf->Write(0, 'TOTAL HARGA', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(38, $ContPosY);
$pdf->MultiCell(20, '', number_format($totalprice, 0, '.', ','), 0, 'R', 0, 1, '', '', true);
$ContPosY+=3;
$pdf->SetXY(1, $ContPosY);
$pdf->Write(0, 'Terbilang :', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetXY(13, $ContPosY);
$pdf->Write(0, [terbilang], '', 0, 'L', true, 0, false, false, 0);

ob_end_clean();

$pdf->Output($_SERVER['SERVER_NAME'] . 'output.pdf','I');

Please help, this is quite urgent
Thank you

When I get this error I insert at the beginning of the code this: ob_end_clean();

I see you have this in the end.
I always do at the beginning

sc_include_lib(“tcpdf”);
sc_include_library(“prj”, “tcpdf_report_lib”, “lib_report_hf.php”, true, true);

m_get_data();

ob_end_clean();

interesting, let me try it. really i never see ob_clean in the beginning, let me update after i try this .
thanks anyway

Don’t ask me why or how.
Years ago, I had an identical mistake, and I corrected it.
But I remembered because I spent quite a bit of time.

hi, i already tried to put ob_clean after declare tcpdf variable, but still same error

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

ob_end_clean();

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('I-CON');
$pdf->SetTitle('Invoice Kutus');
$pdf->SetSubject('Invoice'. [globjual]);
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
//$pdf->AddPage('P','A4'); //A4 Portrait
//$pdf->AddPage('L','A4'); //A4 Landscape

I am curious, have anyone get this error or is it just me, my code really simple and it is not working…:((

Thank you anyway for giving me insight, but still it won’t work, anyway…I change the report PDF invoice by not using code like before, instead I use picture as background for invoice and manually put the position X,Y for field. I still don’t know why the code works in development but not in production

If you can make an export app and tables in the database I can try it on my local server and on 2 different hosting.
But I’m only 2 days in the office. Then I go on vacation for 2 weeks.

okay, i will try,