As easy as 1, 2, 3...
An appearance is the visual representation of a dynamic PDF
element. In simple terms, it is what you see on the screen when you see
a form field or a signature.
There are two different ways for a PDF generation engine to generate appearances:
- It can generate (read: render) the appearance during the PDF generation process.
- It can leave the appearance empty and let the viewer render it.
By default, jPDF uses solution #1. Our generation engine
knows how to render 99% of form field types. Solution #2 presents an
advantage - to delegate processing to the client side. However, you
should consider these limitations:
- The viewer must be smart enough to render appearances.
- You may experience caching issues if you serve your document on a webserver.
Due to the nature of the functionality, enabling or
disabling the generation of the appearance should be done before any
modification is applied to the document.
The following code shows how to deactivate the appearance generation.
// Create a new preference object:
Preferences prefs = new Preferences();
// Deactivate the generation of the appearance:
prefs.setGenerateAnnotations(false);
// Open the template document:
PdfDocument doc = new PdfDocument("MyTemplate.pdf", prefs);
// Start updating the document...
You can change the setting again - once the document is opened - using the following extract.
// Open the template document:
PdfDocument doc = new PdfDocument("Fields.pdf");
// Recover the preference object associated with the document:
Preferences prefs = doc.getPreferences();
// Activate the generation of the appearance:
prefs.setGenerateAnnotations(true);
// Start updating the document...