How do I create a new text field widget with a specific font and font size?

Q: I want to set the font and size of an new empty textfield without
embedding fonts.

a. When using the code below, the CourierBold font is only used when
the field has focus. (Viewed in AcrobatReader9)
b. If I add a default value string Dim f1 As Field = doc.FieldCreate
("xxxxx", Field.Type.e_text,”x”). It complains that I miss a resource.
If I then embed the font, it works. But I do not want to embed any
font as I will use standard font that exist on every windows computer.
And I do not want any prefilled data in the field.

Example-code:

Dim f1 As Field = doc.FieldCreate("xxxxx", Field.Type.e_text)
            f1.SetJustification
(PDF.Field.TextJustification.e_left_justified)
            f1.SetFlag(Field.Flag.e_no_scroll, True)

            Dim annot1 As Annot = Annot.CreateWidget(sdfdoc, New Rect
(100, 100, 200, 150), f1)
            Dim da_str As String = " /Courier-Bold 10 Tf "
            annot1.GetSDFObj().PutString("DA", da_str)
            f1.EraseAppearance()
            f1.RefreshAppearance()
            blank_page.AnnotPushBack(annot1)

How do I solve this?
--------------
A: The following code demonstrates how to create a text field widget
with a given font and font size. Although a font is created it is not
embedded (since it is a standard font). In case you wanted to embed
(and optionally subset) a font you could do so using other
pdftron.PDF.Font.Create???() methods.

PDFNet.Initialize()
PDFNet.SetResourcesPath(...)

Dim doc As PDFDoc = New PDFDoc
Dim blank_page As Page = doc.PageCreate() ' Create a blank page and
some new fields (aka "AcroForms").

Dim f1 As Field = doc.FieldCreate("xxxxx", Field.Type.e_text)
f1.SetJustification(PDF.Field.TextJustification.e_left_justified)
f1.SetFlag(Field.Flag.e_no_scroll, True)

f1.SetValue("Hello!")

Dim annot1 As Annot = Annot.CreateWidget(doc, New Rect(100, 100, 200,
150), f1)

' Set the default appearance.
annot1.GetSDFObj().PutString("DA", " /Courier-Bold 10 Tf ")

' Create the font resource for the default appearance.
Dim resources As Obj = doc.GetAcroForm().PutDict("DR") ' <======
Dim f As Font = Font.Create(doc,
Font.StandardType1Font.e_courier_bold)
resources.PutDict("Font").Put("Courier-Bold", f.GetSDFObj())

blank_page.AnnotPushBack(annot1)
doc.PagePushBack(blank_page)

doc.RefreshFieldAppearances()
doc.Save(output_path + "forms_test1.pdf", 0)
doc.Close()

------------------
You may also want to add new font resources to an existing font
dictionary instead of replacing DR (Default Resources) with new value
each time. For example, you may want to use the following pseudocode:

void AddFontResource(string font_res_name, Font font)
{
Obj acroforms = doc.GetAcroForm();
If (acroforms == null) acroforms = doc.CreateIndirectDict();

Obj dr = acroforms.FindObj("DR");
If (dr == null) dr = acroforms.PutDict("DR");

Obj fnt = dr.FindObj("Font");
If (fnt == null) dr = dr.PutDict("Font");

fnt.Put(font_name, font.GetSDFObj());
}

Then instead of the three lines in the above code, add a new font
resource as follows:

AddFontResource("Courier-Bold", Font.Create(doc,
Font.StandardType1Font.e_courier_bold))

This example shows how to add a (hopefully) small font for use in a field.

First, create your font, you were on the right track here. You can add as a fully embedded font if the size is not too much.

Dim font As Font = Font.CreateTrueTypeFont(doc,"C:\Windows\Fonts\3of9.ttf", True, False) 'True, False means Embed fully

Then, you need to add the font to the AcroForms resources dictionary.

Dim acroform As Obj = doc.GetAcroForm()
If acroform Is Nothing Then
acroform = doc.GetRoot().PutDict("AcroForm")
End If
Dim dr As Obj = acroform.FindObj("DR")
If dr Is Nothing Then
dr = acroform.PutDict("DR")
End If
Dim fonts As Obj = dr.FindObj("Font")
If fonts Is Nothing Then
fonts = dr.PutDict("Font")
End If
fonts.Put("3of9", font.GetSDFObj())

Finally, set this as your default font for that field.

field.PutString("DA", "/3of9 12 Tf 0 g")

If you want to preserve the pre-existing default appearance for the field, and only change the font, see this post.

https://community.pdftron.com/t/freetext-annotation-textstyle/2719/2

If you want to change the font to standard type1 font, available internally in the PDFNet SDK you can do the following instead.

Dim acroform As Obj = doc.GetAcroForm()
If acroform Is Nothing Then
acroform = doc.GetRoot().PutDict("AcroForm")
End If
Dim dr As Obj = acroform.FindObj("DR")
If dr Is Nothing Then
dr = acroform.PutDict("DR")
End If
Dim fonts As Obj = dr.FindObj("Font")
If fonts Is Nothing Then
fonts = dr.PutDict("Font")
End If
dim font As Font = Font.Create(doc, pdftron.PDF.Font.StandardType1Font.e_helvetica)
fonts.Put("helv", font.GetSDFObj())
field.PutString("DA", "/helv 12 Tf 0 g")