FormTemplateDictionary Class
A dictionary of form templates that define annotation appearance states.
Declaration
public class FormTemplateDictionary extends TrackedDictionary<String,FormTemplate>
Remarks
Call the AnnotationAppearance.setForms(value) method to specify named appearance states of an annotation. Each dictionary key is an appearance state name.
The dictionary implements the java.util.Map interface and does not accept null keys. If you add an entry with a null key or pass a null key to the get, containsKey, or remove method, the API throws an ArgumentNullException.
Refer to the following help topic for additional information: Watermark Annotations.
Example: Create a Watermark with Multiple Appearance States
The following code snippet creates a watermark annotation with Approved and Draft appearance states and displays the Draft state:
import java.io.*;
import java.nio.file.*;
import java.util.Map;
import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
public class Main {
public static void main(String[] args) throws Exception {
try (PdfDocument document = new PdfDocument()) {
Page page = document.getPages().add(595, 842);
FormTemplate approved = createStateForm("APPROVED", PdfColor.getGreen());
FormTemplate draft = createStateForm("DRAFT", PdfColor.getRed());
AnnotationAppearance appearance = new AnnotationAppearance();
appearance.setForms(new FormTemplateDictionary(Map.of("Approved", approved, "Draft", draft)));
AnnotationAppearances appearances = new AnnotationAppearances();
appearances.setNormal(appearance);
WatermarkAnnotation watermark = new WatermarkAnnotation(new RectangleF(100, 400, 400, 100));
watermark.setAppearance(appearances);
watermark.setAppearanceName("Draft");
page.getAnnotations().add(watermark);
Files.createDirectories(Path.of("output"));
try (OutputStream stream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
document.save(stream);
}
}
}
static FormTemplate createStateForm(String text, PdfColor color) {
FormTemplate form = new FormTemplate();
form.setBounds(new RectangleF(0, 0, 400, 100));
TextFragment fragment = new TextFragment();
fragment.setText(text);
fragment.setLocation(new PointF(20, 30));
fragment.setFontSize(48);
fragment.setForegroundFill(new SolidFill(color));
form.addFragment(fragment);
return form;
}
}
Inherited Members
Inheritance
Constructors
FormTemplateDictionary() Constructor
Initializes a new instance of the FormTemplateDictionary class.
Declaration
public FormTemplateDictionary()
FormTemplateDictionary(Map<String,FormTemplate> entries) Constructor
Initializes a new instance of the FormTemplateDictionary class with the specified entries.
Declaration
public FormTemplateDictionary(Map<String,FormTemplate> entries)
Parameters
| Name | Type | Description |
|---|---|---|
| entries | java.util.Map<java.lang.String,FormTemplate> | Pairs of appearance state names and form templates to add to the dictionary. |
Exceptions
| Type | Description |
|---|---|
| ArgumentNullException | Thrown if the |
Methods
getSource() Method
Returns the internal dictionary that stores dictionary entries.
Declaration
public FormTemplateDictionary getSource()
Returns
| Type | Description |
|---|---|
| com.devexpress.docs.pdf.internal.FormTemplateDictionary | The internal dictionary. |
Remarks
The getSource() method supports the internal infrastructure of the PDF Document API. Do not call the getSource() method in your code.