views:

86

answers:

1

iTextSharp really, really doesn't like it when I try to create Fonts:

FontFactory.GetFont(Font.HELVETICA, 12)

This gives me a user-friendly StackOverflowException. So I tried this:

new Font(Font.HELVETICA, 12)

which does the same thing. Tried Font.TIMES, and got the same thing, too. So I tried dropping a bit lower based on this answer, which suggests the following:

BaseFont bf = BaseFont.CreateFont(
   HttpContext.Current.Server.MapPath("/path/to/times.ttf"), 
   BaseFont.IDENTITY_H, 
   BaseFont.EMBEDDED);
new Font(bf, 12);

Once again, StackOverflowException. While the consistency is nice, I'd prefer that the library would let me select a font.

I'm sure I've just got some configuration wrong somewhere; but it escapes me as to what it could be.

A: 

I found this article on nabble that suggests creating the font on a separate thread so you have a larger stack to deal with.

FTA

Thread smartCopyThread = new Thread(new ThreadStart(RunSmartCopy),
0x800000);
smartCopyThread.Start();
smartCopyThread.Join();

Here, RunSmartCopy would do the work you're describing.

Joseph
I found that link, too, and all that it accomplishes is that the crash occurs in another thread. This is no small comfort–it avoids the modal dialog that pops up on the server in the crash-on-main-thread case–but it's not conducive to creating the actual PDF.
TALlama