Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Oct 08, 2015 9:33 am

Hi everyone.

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

conxpert
 
Posts: 3
Joined: Fri Sep 25, 2015 7:22 am

Fri Oct 09, 2015 6:58 am

Hi,

Thanks for your inquiry.
Please add this code : pdf.Form.Fields.Add(comboBox); before pdf.SaveToFile(file);.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3011
Joined: Wed Jun 27, 2012 8:50 am

Fri Oct 09, 2015 2:39 pm

Thanks a lot, that helped.

Have a nice weekend.

conxpert
 
Posts: 3
Joined: Fri Sep 25, 2015 7:22 am

Sat Oct 10, 2015 1:27 am

Hi,

Thanks for your reply. Please feel free to write to us if you have any problems.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3011
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF