CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
PDF::API2 - Alignment Issue

 



terrykhatri531
User

Jul 25, 2014, 11:28 AM

Post #1 of 6 (454 views)
PDF::API2 - Alignment Issue Can't Post

Hi,

I am having problems aligning the numbers at right in invoices being created with PDF::API, if you look at the attached picture the values in the Total column are all at the same X axis but there alignment is off, which does not look professional:



Here is the code snippet :




Code
 
$y = $y - 20 ;
$txt->translate($_x = 60, $_y = $y);
$font = $pdf_out->corefont('Helvetica');
$txt->font($font, 10);
$txt->text($prodid);
$txt->translate($_x = 120, $_y = $y);
$txt->text($productname);
$txt->translate($_x = 340, $_y = $y);
$txt->text($quantity);
$txt->translate($_x = 380, $_y = $y);
$txt->text($unitprice);
$txt->translate($_x = 450, $_y = $y);
$txt->text($discount);
$txt->translate($_x = 495, $_y = $y);
$txt->text($total,align => 'right');
$txt->translate($_x = 300, $_y = 150);
$txt->text('Freight................');
$txt->translate($_x = 495, $_y = 150);
$txt->text($freight,align => 'right');
$txt->translate($_x = 495, $_y = 120);
$txt->text($invttl,align => 'right');



Many many thanks !!

Terry
Attachments: AlignmentIssue.png (58.5 KB)


BillKSmith
Veteran

Jul 26, 2014, 6:19 AM

Post #2 of 6 (437 views)
Re: [terrykhatri531] PDF::API2 - Alignment Issue [In reply to] Can't Post

Try using a monospace font for the entire document.
Good Luck,
Bill


terrykhatri531
User

Jul 26, 2014, 8:13 AM

Post #3 of 6 (432 views)
Re: [terrykhatri531] PDF::API2 - Alignment Issue [In reply to] Can't Post

Hi Chris,

The following line in my script is giving warning and addition is not being calculated accurately, how do I fix that


Code
 
my $invttl = $ordttl + $freight;




Warning is :

Argument " 1,076.5..." isn't numeric in addition (+) at invoice.pl line 121



Many thanks !!!

Terry


FishMonger
Veteran / Moderator

Jul 26, 2014, 8:28 AM

Post #4 of 6 (431 views)
Re: [terrykhatri531] PDF::API2 - Alignment Issue [In reply to] Can't Post

perl is seeing "1,076.5" as a string, not a number. Remove the comma before doing the addition.


terrykhatri531
User

Jul 26, 2014, 9:03 AM

Post #5 of 6 (428 views)
Re: [FishMonger] PDF::API2 - Alignment Issue [In reply to] Can't Post

Ok, then How do I format it back using perl ? is there a function in perl that can format it back in the mask like 999,999.99

Thanks

Terry


FishMonger
Veteran / Moderator

Jul 26, 2014, 9:23 AM

Post #6 of 6 (425 views)
Re: [terrykhatri531] PDF::API2 - Alignment Issue [In reply to] Can't Post

perldoc -q "How can I output my numbers with commas added?"
http://perldoc.perl.org/perlfaq5.html#How-can-I-output-my-numbers-with-commas-added?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives