Code works in example, but not my app

I am using the EddiesElectronics PDF web example to try to figure out how to make a PDF. Most of it works as expected, but trying to right justify a date has me baffled. My code is

var d As DateTime = DateTime.Now
var dayString As String = d.ToString(locale.Current, DateTime.FormatStyles.Full, DateTime.FormatStyles.Medium)
var b As double = Session.Document.Graphics.TextWidth(dayString)
Session.Document.Graphics.DrawText(dayString, Session.Document.Graphics.Width - x - round(Session.Document.Graphics.TextWidth(dayString)), y)

where x is the left offset from the margin and y is the height. I added the b double for troubleshooting.

In my app, b always comes out 0, even if I hard code a string value instead of the dayString variable. When I pasted this code into the EE example and substituted hard values for x and y, it works properly. I figure I am either missing something in the setup of the PDF document or my app is using too much memory for this function. Any suggestions would be greatly appreciated.

I plugged your code into my pdf and it works as expected. What are you supplying for x and y?

x=60, y=120. I am trying to do it without the preview. Maybe that is the problem.

The problem is that the TextWidth function works with the Times font but not Helvetica. See bug report 62326.

Insert this code into the EE-PDF-Web example somewhere where the Helvetica font is active.

var a As Double = Session.Document.Graphics.TextWidth(“Bug Report”)
Session.Document.Graphics.FontName = PDFDocument.StandardFontNames.Times
var b As Double = Session.Document.Graphics.TextWidth(“Bug Report”)
break