Welcome Guest, Not a member yet? Register   Sign In
TCPDF Generate incomplete page (Need help fast)))
#1

Hi, I want to ask why when i change value from my table on DB, TCPDF not generate complete page. Here the example : i have table called orders and there status column (it ranges from 0-6), when order have 5 in its status column the TCPDF generate page flawlessly, but when i change the status column to 0-3, TCPDF generate incomplete page.

I literally doesnt know what i missed in my codes
Here my code:

Controller :
PHP Code:
function printorder($idorder)
    {
        
$order $this->order_model->getorderforprint($idorder)->result();

        
$i 0;
        
$tmp = array();
        
$temp2 = array();
        foreach (
$order as $key) {

            
$temp $this->order_model->getcompleteoneorder($key->id)->result();
            
$j=0;
            foreach (
$temp as $key2) {
                
$temp2[$j] = array(
                            
'namabarang' => $key2->nama_barang,
                            
'size' => $key2->size,
                            
'jumlah' => $key2->quantity,
                            
'harga' => $key2->price,
                        );
                
$j++;
            }

            
$tmp[$i] = array(
                    
'id' =>$key->id,
                    
'nama' => $key->first_name,
                    
'tanggal' => $key->date,
                    
'status' => $key->order_status,
                    
'alamat' => $key->alamat,
                    
'ongkir' => $key->ongkir,
                    
'ekspedisi' => $key->ekspedisi.' '.$key->paketekspedisi,
                    
'pembayaran' => $key->statusbayar,
                    
'barang' => $temp2,
                );
            
$i++;

        }
        
$this->data['detail'] = $tmp;
        
$this->load->view('admin/order/pdfperorder'$this->data);
    } 

PDF View :
PHP Code:
<?php
$pdf 
= new TCPDF(PDF_PAGE_ORIENTATIONPDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetHeaderData('',''PDF_HEADER_TITLEPDF_HEADER_STRING);
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setFontSubsetting(false);
$pdf->SetFont('helvetica'''14''true);
ob_start();
foreach (
$detail as $key) {
$yyyy substr($key['tanggal'], 0,4); $mm substr($key['tanggal'], 5,2); $dd substr($key['tanggal'], 8,2);
$pdf->SetTitle('Order '.$key['nama'].' '.$dd.'-'.$mm.'-'.$yyyy);
$pdf->SetSubject('Order');
    
?>
    <head>
<style>
body {
    background-color: linen;
}
table.pdf1{
    border: 1px solid black;
}
tr.pdf1{
    border: 1px solid black;
}
td.pdf1{
    border: 1px solid black;
}
th.pdf1{
    border: 1px solid black;
}
.mid{
    text-align: center;
}
.right{
    text-align: right;
}
</style>
</head> 
    <table class="">
        <tr>
            <td width="110px">Nama</td>
            <td width="15px">:</td>
            <td width="520px"><?php echo $key['nama']; ?></td>
        </tr>
        <tr>
            <td>Tanggal</td>
            <td>:</td>
            <td><?php echo $dd.'-'.$mm.'-'.$yyyy?></td>
        </tr>
        <tr>
            <td>Status</td>
            <td>:</td>
            <td><?php echo $key['status']; ?></td>
        </tr>
        <tr>
            <td>Alamat</td>
            <td>:</td>
            <td><?php echo $key['alamat']; ?></td>
        </tr>
        <tr>
            <td>Ekspedisi</td>
            <td>:</td>
            <td><?php echo strtoupper($key['ekspedisi']); ?></td>
        </tr>
        <tr>
            <td>Ongkir</td>
            <td>:</td>
            <td><?php echo "Rp " .number_format($key['ongkir'],0,',','.'); ?></td>
        </tr>
        <tr>
            <td>Pembayaran</td>
            <td>:</td>
            <td><?php echo $key['pembayaran']; ?></td>
        </tr>
        <tr>
            <td>Barang</td>
            <td>:</td>
        </tr>
    </table>
    <br><br>
    <table class="pdf1">
        <tr class="pdf1">
            <th width="40px" class="pdf1">NO</th>
            <th width="230px" class="pdf1">Nama Barang</th>
            <th width="65px" class="pdf1">Ukuran</th>
            <th width="65px" class="pdf1">Jumlah</th>
            <th width="120px" class="pdf1">Harga</th>
            <th width="120px" class="pdf1">Subtotal</th>
        </tr>
        <?php 
        $i
=1;
        
$grandtotal 0;
        foreach (
$key['barang'] as $key2) { ?>
            <tr class="pdf1">
                <td class="pdf1 mid"><?php echo $i?></td>
                <td class="pdf1"><?php echo $key2['namabarang']; ?></td>
                <td class="pdf1 mid"><?php echo $key2['size']; ?></td>
                <td class="pdf1 mid"><?php echo $key2['jumlah']; ?></td>
                <td class="pdf1 mid"><?php echo "Rp " .number_format($key2['harga'],0,',','.'); ?></td>
                <td class="pdf1 right"><?php echo "Rp " .number_format($key2['jumlah']*$key2['harga'],0,',','.'); ?></td>
            </tr>
        <?php $grandtotal $grandtotal + ($key2['jumlah']*$key2['harga']); $i++;} ?>
        <tr>
            <th colspan="5"  class="pdf1"><center>Jumlah</center></th>
            <td class="pdf1 right"><?php echo "Rp " number_format($grandtotal,0,',','.'); ?></td>
        </tr>
        <tr>
            <th colspan="5"  class="pdf1"><center>Jumlah + Ongkir</center></th>
            <td class="pdf1 right"><?php echo "Rp " number_format($grandtotal+$key['ongkir'],0,',','.'); ?></td>
        </tr>
    </table>
    
    <?php 
    $pdf
->AddPage();
    
$cont ob_get_contents();
    
$pdf->writeHTML($conttruefalsetruefalse'');
    
ob_end_clean();
}
$pdf->IncludeJS("print();");
$pdf->Output('Order '.$key['nama'].' '.$dd.'-'.$mm.'-'.$yyyy.'.pdf''I');
?>

Model :
PHP Code:
function getorderforprint($idorder)
    {
        
$this->db->select("cm_tb_orders.id, users.first_name, cm_tb_orders.date, cm_order_status.order_status, cm_tb_orders.ongkir, cm_tb_orders.alamat, cm_tb_orders.ekspedisi, cm_tb_orders.paketekspedisi, CASE WHEN cm_tb_orders.statusbayar = 0 THEN 'Belum Bayar' ELSE 'Sudah Bayar' END AS statusbayar");
        
$this->db->from('cm_tb_orders');
        
$this->db->join('cm_order_status','cm_tb_orders.status = cm_order_status.id');
        
$this->db->join('users','cm_tb_orders.customerid = users.id');
        
$this->db->where('cm_tb_orders.id'$idorder);
        return 
$this->db->get();
    } 
Reply
#2

@Akihiko,

Have you run the query to see what the output is when you have a different values for cm_tb_orders.id?
Reply
#3

(02-06-2018, 06:44 PM)php_rocs Wrote: @Akihiko,

Have you run the query to see what the output is when you have a different values for cm_tb_orders.id?

Yes, i have run it on sql tab on phpmyadmin and it's show the data perfectly.

Also i just run the pdf view again but with the tcpdf syntax deleted(just normal view), the data output is the same like i use direct query from phpmyadmin. So it think the error was on the pdf view file. but i dont know where.
Reply
#4

Did you try unset on $key and $key2 ?

Newer versions of PHP do not reset the foreach variables.

Read the PHP foreach documentation on php.net
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

@Akihiko,

Also, have you dumped out the $tmp array to make sure that the data is correct in both instances? Exactly where does the PDF stop in it's generation of the page?
Reply
#6

(02-07-2018, 04:16 AM)InsiteFX Wrote: Did you try unset on $key and $key2 ?

Newer versions of PHP do not reset the foreach variables.

Read the PHP foreach documentation on php.net

hey i just read the foreach documentation, did you mean unset() syntax? i think the iteration just fine, because when i iterate with TCPDF syntax on the view (e.g $pdf->SetCreator().... etc) and if the status column from DB is 0 - 3 the page is stop generating in various place, but if i erase all TCPDF syntax and leave only foreach iteration the view is printed perfectly even the status 0 - 3, which means the foreach is working just fine but TCPDF is not, what do you think?

(02-07-2018, 11:21 AM)php_rocs Wrote: @Akihiko,

    Also, have you dumped out the $tmp array to make sure that the data is correct in both instances?  Exactly where does the PDF stop in it's generation of the page?

Yes, i already try print the page without TCPDF syntax and it printed fine, if the status column on DB is 3, the table generated with only one incomplete row so the jumlah, harga, subtotal on that row is not printed with the rest of barang on that table, when the status column is 2 or 1 the PDF just generated till barang: without table below it, if the status colum on DB is 0 the PDF generated nothing just white PDF page, what do you think?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB