public class FieldDocProperty extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves the indicated document information.
Examples:
Shows how to use DOCPROPERTY fields to display document properties and variables.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Below are two ways of using DOCPROPERTY fields.
// 1 - Display a built-in property:
// Set a custom value for the "Category" built-in property, then insert a DOCPROPERTY field that references it.
doc.getBuiltInDocumentProperties().setCategory("My category");
FieldDocProperty fieldDocProperty = (FieldDocProperty) builder.insertField(" DOCPROPERTY Category ");
fieldDocProperty.update();
Assert.assertEquals(fieldDocProperty.getFieldCode(), " DOCPROPERTY Category ");
Assert.assertEquals(fieldDocProperty.getResult(), "My category");
builder.insertParagraph();
// 2 - Display a custom document variable:
// Define a custom variable, then reference that variable with a DOCPROPERTY field.
Assert.assertTrue(doc.getVariables().getCount() == 0);
doc.getVariables().add("My variable", "My variable's value");
FieldDocVariable fieldDocVariable = (FieldDocVariable) builder.insertField(FieldType.FIELD_DOC_VARIABLE, true);
fieldDocVariable.setVariableName("My Variable");
fieldDocVariable.update();
Assert.assertEquals(" DOCVARIABLE \"My Variable\"", fieldDocVariable.getFieldCode());
Assert.assertEquals("My variable's value", fieldDocVariable.getResult());
doc.save(getArtifactsDir() + "Field.DOCPROPERTY.DOCVARIABLE.docx");
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, update