|
|||||||||||||||||||||||||||||||||||||||||||||
TUTORIALS Creating and changing
|
|||||||||||||||||||||||||||||||||||||||||||||
|
<body>
|
The element at the root of the XML document. We will see in section 3 that it requires attributes. |
|
<p>
|
Encloses text that is interpreted as a paragraph. It may take style attributes - see below. |
|
<i>
|
Encloses text that is displayed in an italic font. |
|
<b>
|
Encloses text that is displayed in a bold font. |
|
<span>
|
Groups text solely for the purpose of applying styles - see below. |
|
<br>
|
Starts a new line. Applies to multi-line fields. |
|
Attribute
|
Value
|
Description
|
| text-align |
keyword
|
Horizontal alignment. Possible values: left, right, center. |
| vertical-align |
decimal
|
An amount by which to adjust the baseline of the
enclosed text. A positive value indicates a superscript; a negative
value indicates a subscript. The value is of the form <decimal
number>pt, optionally preceded by a sign, and followed by
“pt”. Examples: -3pt, 4pt. |
font-size |
decimal
|
The font size of the enclosed text. The value is of the form: <decimal number>pt. |
| font-style |
keyword
|
Specifies whether the enclosed text should be displayed using a normal or italic (oblique) font. Possible values: normal, italic. |
| font-weight |
keyword
|
The weight of the font for the enclosed text. Possible values: normal, bold, 100, 200, 300, 400, 500, 600, 700, 800, 900. Note: normal is equivalent to 400, and bold is equivalent to 700. |
| font |
list
|
A shorthand CSS font property of the form font:<font-style> <font-weight> <font-size> <font-family>. |
| font-family |
list
|
A font name or list of font names to be used to display
the enclosed text. (If a list is provided, the first one containing
glyphs for the specified text is used.) |
| color |
RGB value
|
The color of the enclosed text. The value is an RGB
value specified in the sRGB color space: <http://www.srgb.com>).
It can be in one of two forms: • #rrggbb with a 2-digit hexadecimal value for each component. • rgb(rrr,ggg,bbb) with a decimal value for each component. |
| text-decoration |
keyword
|
One of the following keywords: • underline: The enclosed text should be underlined. • line-through: The enclosed text should have a line drawn through it. |
| font-stretch |
keyword
|
Specifies a normal, condensed or extended face from a font family. Supported values from narrowest to widest are: ultra-condensed,
extra-condensed, condensed, semi-condensed, normal, semi-expanded,
expanded, extra-expanded, and ultra-expanded. |
In the following example, we will create a document with its RichText form field. For more details about form field creation please refer to this tutorial.
// Create a document in memory and its first page:
PdfDocument doc = new PdfDocument();
Page.createInstance(doc);// Create a multi-line, RichText form field:
Rectangle rect = new Rectangle(100, 100, 100, 100);
TextField field = TextField.createInstance(doc, "RichTextField", 1, rect);
field.setMultiline(true);
field.setRichText(true);Once a form field has its RichText flag activated, it can only accept values which comply with the XML description given in section #1.
Similarly, the getValue() method will return the associated XML description (if any).
Here come the easy part - setting the value. The most difficult part is to compose the document itself. Please refer to section #1 for a detailed decription of the XML grammar. One important thing to mention is the attributes on the body tag: they are mandatory. Failure to use these attributes will cause the field to be interpreted as a standard text field.
// Now set its value using a RichText XML:
field.setValue("<?xml version=\"1.0\"?><body xfa:APIVersion=\"Acroform:2.4.5292.0\" xfa:spec=\"2.1\" xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\"><p><b>RichText Content</b></p><p style=\"color:#009900\">Style 1</p><p><b><i>Style 2</i></b></p><p style=\"text-align:right;text-decoration:underline;color:#FF0000\">Style 3</p></body>");// Save and close the modified document:
doc.saveAs("MyDocument.pdf");
doc.close();The generated file should look like this screenshot:
| © 2000-2007 Crionics Inc. |