Jun 4, 2011 at 1:59 PM
Edited Jun 5, 2011 at 10:15 AM
I do not get it what the word-wrap problem would be in this situation.
I do understand that using xFontRegular.Height will give the Height.
However my problem isn't the height, my problem with MeasureString is that it doesn't correctly measure the width.
I want to outline money so that it is outlined on the right side.
To get the X-point value I do:
page.Width - 100 - gfx.MeasureString(item.price.Value.ToString(), font).Width
This should give the X-point where I should draw my string so that the money is outlined on the right at 100 from the page.width.
And no matter what I try it just will not do this correctly, it is not outlined on the right side.
It appears that gfx.MeasureString(item.price.Value.ToString(), font).Width is always zero.
If I add: XStringFormat and use that in my call to gfx.DrawString, like:
xsf = new
xsf.LineAlignment = PdfSharp.Drawing.XLineAlignment.BaseLine;
Than all over sudden, measurestring produces a result. However there are 2 strange things:
1) If I let it build the same PDF twice. than both are not identical. The first call goes well, than all other calls the money is positioned almost outside the page.
Where as when I let it build the same PDF for the second, third, etc time then this will no longer happen. Using the debugger, the calculated X-position is the same no matter if it builds the PDF for the first or second time. It appears that by just using
MeasureString something goes wrong
2) Although it produces different results for different strings. The money isn't outlined on the right-side. 999,99 is about half a character to far to the left than 99,99.
In my samples the money figures in the hundreds are al at the first line and the money figures in tenths are sedond line and more. So theoretically it could be a matter of misalligning the first line (just haven't tested that yet).
I think my one and only solution is to left allign each character in the amount of money. In that way at least all characters will be alligned.