I'm pretty sure there's an answer to my question somewhere but I didn't find it here in the forums nor in the documentation. I'm trying to set the font for my PdfComboBoxField items. Here's what I expected to work in my C# application:
- Code: Select all
using (PdfDocument pdf = new PdfDocument())
{
PdfPageBase page = pdf.Pages.Add(PdfPageSize.A4, new PdfMargins());
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Regular));
RectangleF labelBounds = new RectangleF(20, 20, 40, font.Height);
page.Canvas.DrawString("My label", font, PdfBrushes.Black, labelBounds);
PdfComboBoxField comboBox = new PdfComboBoxField(page, "cmb");
comboBox.Bounds = new RectangleF(80, 20, 80, font.Height);
comboBox.Font = font;
comboBox.Items.Add(new PdfListFieldItem("value 1", "text 1"));
comboBox.Items.Add(new PdfListFieldItem("value 2", "text 2"));
comboBox.Items.Add(new PdfListFieldItem("value 3", "text 3"));
string file = string.Format(@"c:\Temp\{0}.pdf", Guid.NewGuid().ToString());
pdf.SaveToFile(file);
System.Diagnostics.Process.Start(file);
}
I've tried to simplify it as much as possible. The problem is: The PdfTrueTypeFont is working for the label, but not for the PdfComboBoxField items. However, I haven't found an alternative way of assigning the font directly to the items. Can anyone help me out?
Thanks in advance,
Tobi