Q: This topic has several articles in the KB, but perhaps not on point
for fields instead of annotations.
1. I'd like the few lines of code here vetted. I couldn't find an
example for fields. Is this the way to do this?
2. I'd suggest a KB entry specifically addressing changing field
3. Where are the parameters passed in the string "/Arial 10 Tf 1 0 0
rg " and the string format documented? And the keys ("DA", for
Experience helps: "Tf" must be text field; the last 3 fields are RGB
values. The answer would answer questions such as: Can I write x'ff'?
Where do the letter values like "rg" come from?
Dim docPDF as PDFDoc
Dim sdfObjFld as SDF.Obj
Dim fldField as Field
Dim strFieldName as String = "SampleFieldName"
Dim strFieldValue as String = "Sample Field Value"
fldField = docPDF.GetField(strFieldName)
If Not fldField Is Nothing Then
sdfObjFld = fldField.GetSDFObj()
If Not sdfObjFld Is Nothing Then
sdfObjFld.PutString("DA", "/Arial 10 Tf 1 0 0 rg ")
A: The format for DA (i.e. Default Appearance) is documented in PDF
Reference Manual (http://www.pdftron.com/downloads/PDFReference16.pdf,
Table 8.71 in Chapter 8.6.2)
The default appearance string contains a sequence of valid page-
content graphics or text state operators that define such properties
as the field’s text size and color. The operators are documented in
Appendix A "Operator Summary" in PDF Reference.
The following are the relevant paragraphs from Chapter 8.6.2.
"The default appearance string (DA) contains any graphics state or
text state operators needed to establish the graphics state
parameters, such as text size and color, for displaying the field’s
variable text. Only operators that are allowed within text objects may
occur in this string (see Figure 4.1 on page 197). At a minimum, the
string must include a Tf (text font) operator along with its two
operands, font and size. The specified font value must match a
resource name in the Font entry of the default resource dictionary
(referenced from the DR entry of the interactive form dictionary; see
Table 8.67). A zero value for size means that the font is to be auto-
sized: its size is computed as a function of the height of the
annotation rectangle. The default appearance string should contain at
most one Tm (text matrix) operator.
If this operator is present, the viewer application should replace the
and vertical translation components with positioning values it
determines to be appropriate, based on the field value, the quadding
(Q) attribute, and any layout rules it employs. If the default
appearance string contains no Tm operator, the viewer should insert
one in the appearance stream (with appropriate horizontal and vertical
translation components) after the default appearance string and before
the text-positioning and text-showing operators for the variable
"Operator rg (r g b rg) sets the fill color space to DeviceRGB and set
the color to use for filling operations.
Each operand must be a number between 0.0 (minimum intensity) and 1.0
"rg" is a shorthand for "Set RGB values for fill color".
"Tf" is a shorthand for "Set font and font size".
"Tm" is a shorthand for "Set text matrix".
"Tc" is a shorthand for "Set text character spacing".
The following are examples of DA strings:
// Set font size to 10 pts. Set text color to black (0, 0, 0).
fld.PutString("DA", "/Arial 10 Tf 0 0 0 rg ");
// Auto-size font (font size = 0). Set text color to red (1, 0, 0).
fld.PutString("DA", "/Arial 0 Tf 1 0 0 rg ");
// Set font size to 14 pts. Set text color to green (0, 0, 1).
fld.PutString("DA", "/Arial 0 Tf 0 0 1 rg ");
// Auto-size font (font size = 0). Set character spacing (Tc) to 0.25.
Set text color to gray (0.5, 0.5, 0.5).
fld.PutString("DA", "/Courier 0 Tf 0.25 Tc 0.5 0.5 0.5 rg ");
// Set the explicit text matrix (scale text 0.5 horizontally, 1.5
times vertically, offset by [10,20]).
fld.PutString("DA", "/Courier 12 Tf 0.5 0 0 1.7 10 20 Tm ");