# How to print Number with Align Right

Dear gurus,

I have trouble printing invoice, I manage to print the list of goods in PDF, but the alignemnt kinda mess

//qty goods
\$ContPosY1=62;
\$qty_prod = [qtybrg];
\$arr_qty_prod = explode(".",\$qty_prod);
foreach(\$arr_qty_prod as \$typeName){
\$pdf->SetXY(30, \$ContPosY1);
\$pdf->Write(0, \$typeName, ‘’, 0, ‘R’, true, 0, false, false, 0);
\$ContPosY1+=4;
}

//price goods
\$ContPosY2=62;
\$price_prod = [pricebrg];
\$arr_price_prod = explode(".",\$price_prod);
foreach(\$arr_price_prod as \$typeName2){
\$pdf->SetXY(20, \$ContPosY2);
\$pdf->Write(0, \$typeName2, ‘’, 0, ‘R’, true, 0, false, false, 0);
\$ContPosY2+=4;
}

//price*qty
\$ContPosY3=62;
\$tot_prod = [totprice];
\$arr_tot_prod = explode(".",\$tot_prod);
foreach(\$arr_tot_prod as \$typeName3){
\$pdf->SetXY(30, \$ContPosY3);
\$pdf->Write(0, \$typeName3, ‘’, 0, ‘R’, true, 0, false, false, 0);
\$ContPosY3+=4;
}

Now the price, qty and subtotal align to right alltogether. how can I do align right for each row as normal

thanks

For each line to be left-aligned after a sum personally I would create a line beginning with the statement ‘L’ for a line Text,
for a line integer a line with the instruction ‘R’, just realign to left the next line etc, otherwise the instruction remains the same until the next alignment change.
maybe see also the use of cell and multicell in tcpdf, it would avoid you having to parametrer too many lines where as often multicell would be enough,
https://tcpdf.org/
ex:
\$pdf->multiCell(20, ‘’, “Total GF”, 1, ‘R’, 0, 0, ‘’, ‘’, true, 0, false, false,’’, ‘M’,true);

nice, i will try this…i will update after I try this…

it worked, big thanks.
Now one last mission, how to multicell /write variable into currency format, I have variabel with currency (say 230000), how to change it into “230,000” inside multicell

thanks

update : ahh…i am really basic at PHP, apparently there is PHP function called number_format
now, it works

ex:
\$val = 230000;
\$test = number_format(\$val);
echo \$test.’</br>’;
IN Event, On Record:

\$val = 230000;
\$test = number_format(\$val);

IN pdf layout:
val_color = 0 --> BLACK.
val_color = 255 --> Red.

\$val_color_init= 0;// Initialize the val for color to Black;
\$val_color = 0;
\$pdf->multiCell(15, 7,\$pdf->SetTextColor(\$val_color_init,0,0).\$pdf->SetTextColor(\$val_color,0,0).\$test, 1, ‘R’, 0, 0, 50, 85, true, 0, false, true,’’, ‘T’,true);

nice, really teach me something more about SC, actually PHP…
I know this is out of thread topic, now i have problem to show records from recordset/table database to be shown on pdf report with grid/table
I want to make invoice, so the grid/table will be filled with records.

can i use EOD format ? (link : https://tcpdf.org/examples/example_048/)