Print Page | Close Window

formatting a column of currency

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2488
Printed Date: 04 Apr 26 at 8:03PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: formatting a column of currency
Posted By: glennh
Subject: formatting a column of currency
Date Posted: 13 Jan 13 at 12:52AM
I'm working on a table of financial transactions. typical kind of format:

date   description amount balance

In an attempt to keep things simple (maybe a bit of laziness), I'm making 4 strings with a CRLF delimiting each line then using the FitTextBox function to draw the data. 

My biggest problem here is that I'm losing the white space at the beginning of my lines. Say my first two lines are like this: 

-$123.45
 $ 45.67

I'm losing the space before the dollar sign on the second line when using FitTextBox. Is there any way around this? 

A secondary issue is that I'm using the helvetica font which is proportional. My numbers don't line up well, so I've been making my currency column use the Courier font, but I'm not crazy about the way that looks with two different fonts being used on one (pseudo) line. 

Any help/advice on either of these issues would be appreciated. 

Thanks!



Replies:
Posted By: edvoigt
Date Posted: 16 Jan 13 at 7:59PM
Hi Gleen,

you want a nice looking solution. Everything has a price in coffee and time. For deeper knowledge look on my answer in this post:
http://www.quickpdf.org/forum/tquickpdf0813drawtext_topic2074_post8841.html - http://www.quickpdf.org/forum/tquickpdf0813drawtext_topic2074_post8841.html

and something more here:
http://www.quickpdf.org/forum/word-wrapping_topic2040_post8977.html - http://www.quickpdf.org/forum/word-wrapping_topic2040_post8977.html
This only to show you some background. The best idea is to look deeper in the reference guide. But now my idea.

There are different stages of accuracy. Lets start with the wished font (not Courier). We look only to realize one line correct, more later. We need the position of decimalseparator as given. Then we play with QP.SetTextAlign. With QP.SetTextAlign(1) we may draw the separator. If we know the width of the separator-sign (QP.Charwidth), it is easy to draw the both part of the string with SetTextAlign(0) respectivly SetTextAlign(2). If you know how much is the lineheight (see in my answers above). you may draw the next line in the same manner.

May it's good enough for your purposes. But you'll see, that the digits are not in columns, because the font ist of variable pitch. A 8 is bigger than a 1. With more work you may set every glyph step by step alone to simulate fixed pitch.


Cheers,

Werner


Posted By: glennh
Date Posted: 16 Jan 13 at 9:59PM
Herzlichen Dank, Werner!

I'll review that information, I appreciate it!


Posted By: glennh
Date Posted: 16 Feb 13 at 11:54PM
Following back on this. Turns out this wasn't that difficult at all. I just used right alignment with drawtext and the currency amounts lined up great. 



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk