Class AnnotationText
- java.lang.Object
-
- org.faceless.pdf2.PDFAnnotation
-
- org.faceless.pdf2.AnnotationText
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class AnnotationText extends PDFAnnotation
This class represents the type ofPDFAnnotation
created by the "Text Markup" tool in Acrobat. This is simply a box which may contain one or more lines of text.- Since:
- 2.3.7
-
-
Constructor Summary
Constructors Constructor Description AnnotationText()
Create a new Text annotation
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
clone()
PDFStyle
getBackgroundStyle()
Get the background style for the annotationfloat[]
getCallout()
Get the callout points, as set bysetCallout(float[])
java.lang.String
getCalloutEnding()
Get the type of Line-Ending, as set bysetCalloutEnding(java.lang.String)
java.awt.Color
getColor()
Return the background color of the annotation - since 2.11, the equivalent of callinggetBackgroundStyle().getFillColor()
float[]
getContentRectangle()
Return the rectangle of the content of this annotation.java.lang.String
getRichTextContents()
Get the rich-text content of this annotation if specified, ornull
if only plain-text content is availablePDFStyle
getStyle()
Get the text style of the annotation.void
putLiteral(java.lang.String key, java.lang.String tokens)
Put a literal token sequnce.void
putRichTextResource(java.lang.String key, java.lang.Object value)
Add a resource that is referenced by the rich content set insetRichTextContents(java.lang.String)
.void
rebuild()
Rebuild the annotation's appearance.void
setBackgroundStyle(PDFStyle style)
Set the background style for the annotation.void
setCallout(float[] cl)
Set the "Callout" for this box.void
setCalloutEnding(java.lang.String type)
Set the type of Line-Ending that's used to mark the end of a callout - an arrow, circle or similar.void
setColor(java.awt.Color color)
Set the background color of the annotation.void
setContentRectangle(float x1, float y1, float x2, float y2)
Set the rectangle of the content of this annotation.void
setContents(java.lang.String content)
Set the contents of the annotation.void
setRichTextContents(java.lang.String content)
Set the Rich-text contents of the annotation.void
setStyle(PDFStyle style)
Set the style to display the text injava.lang.String
toString()
-
Methods inherited from class org.faceless.pdf2.PDFAnnotation
addPropertyChangeListener, addReview, flatten, getAction, getAssociatedFiles, getAuthor, getContents, getCreationDate, getDefaultColorSpace, getInReplyTo, getLocale, getMetaData, getModifyDate, getOpacity, getOptionalContentDescriptor, getPage, getPopup, getRectangle, getReplies, getReviews, getSubject, getType, getUniqueID, getUserData, getXMP, hasAppearanceState, isContentLocked, isPositionLocked, isPrintable, isReadOnly, isVisible, putUserData, removePropertyChangeListener, setAction, setAuthor, setCreationDate, setDefaultColorSpace, setInReplyTo, setLocale, setLocked, setMetaData, setModifyDate, setOpacity, setOptionalContentDescriptor, setPage, setPrintable, setReadOnly, setRectangle, setSubject, setUniqueID, setVisible
-
-
-
-
Method Detail
-
setContents
public void setContents(java.lang.String content)
Set the contents of the annotation. If there is anyrich-text Content
, this method will overwrite it.- Overrides:
setContents
in classPDFAnnotation
- Parameters:
content
- the content of the Text annotation. May contain "\n" characters to indicate newlines
-
setRichTextContents
public void setRichTextContents(java.lang.String content)
Set the Rich-text contents of the annotation. This method takes an XML-formatted "Rich Text String" as defined in the PDF Specification, chapter 8. Broadly this is a highly simplified XHTML document containing a <body>, one or more <p> tags which contain zero or more <span>, <i> and <b> tags. The only permitted attribute is "style". An example would be:
<?xml version="1.0"?> <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:9.0.0" xfa:spec="2.0.2" style="font-size:14pt;text-align:left;color:#000000;font-weight:normal;font-style:normal;font-family:Helvetica,sans-serif"> <p> <span>This text is <i>italic</i> and this is in <span style="color:#FF0000">red </span> </p> <p> <span>This is the next line of text</span> </p> </body>
Note that due to quirks in Acrobat, newlines in the text should be indicated with a " " character as well as with a paragraph end. Failing to do so will lose the rich-text formatting if the field is subsequently edited in Acrobat.
Calling this method will also update the plain-text version of the Content, as returned by
PDFAnnotation.getContents()
.- Parameters:
content
- a Rich Text String- Throws:
java.lang.IllegalArgumentException
- if the supplied content is not well formed XHTML.- Since:
- 2.11
- See Also:
setContents(java.lang.String)
,PDFAnnotation.getContents()
,getRichTextContents()
-
putRichTextResource
public void putRichTextResource(java.lang.String key, java.lang.Object value)
Add a resource that is referenced by the rich content set insetRichTextContents(java.lang.String)
. For example, if the rich content included a<span style='font-family:MyFont'>
you would need to make theMyFont
font available to the annotation by doingputRichTextResource("MyFont", font)
, wherefont
is aPDFFont
.- Parameters:
key
- the name of the resourcevalue
- the resources - any object, but typically aPDFFont
ornull
to remove a previously set value.- Since:
- 2.11.25
-
getRichTextContents
public java.lang.String getRichTextContents()
Get the rich-text content of this annotation if specified, ornull
if only plain-text content is available- Since:
- 2.11
-
setStyle
public void setStyle(PDFStyle style)
Set the style to display the text in- Parameters:
style
- the style to display the text in
-
setBackgroundStyle
public void setBackgroundStyle(PDFStyle style)
Set the background style for the annotation.- Since:
- 2.11
-
getStyle
public PDFStyle getStyle()
Get the text style of the annotation.
-
getBackgroundStyle
public PDFStyle getBackgroundStyle()
Get the background style for the annotation- Since:
- 2.11
-
getColor
public java.awt.Color getColor()
Return the background color of the annotation - since 2.11, the equivalent of callinggetBackgroundStyle().getFillColor()
- Overrides:
getColor
in classPDFAnnotation
-
setColor
public void setColor(java.awt.Color color)
Set the background color of the annotation.- Overrides:
setColor
in classPDFAnnotation
-
setCallout
public void setCallout(float[] cl)
Set the "Callout" for this box. Since Acrobat 7.0 a Text annotation may have a "callout arrow" which is drawn in one or two segments from the box itself. The paramater "cl" is an array of 4 or 6 floats - the first two parameters are the point the callout points to, the last two parameters are the point the line joins onto the box, and if the array is 6 items long, the middle two points are the "elbow" of the line. A value of
null
removes the callout line.As an example, if the rectangle of the box is (100, 100, 200, 200), a callout could be specified as (0, 0, 0, 150, 100, 150) to draw a line from the bottom-left of the page up the left hand side, and then across to join the box in the middle.
If the first point of the callout is inside the box itself, an
IllegalArgumentException
is thrown. Otherwise the points will be adjusted if necessary to join onto the box in a sensible manner.- Parameters:
cl
- the callout points - either an array of 4 points as (x1, y1, x2, y2), or an array of 6 points as (x1, y1, x2, y2, x3, y3)- Since:
- 2.11.7
-
setCalloutEnding
public void setCalloutEnding(java.lang.String type)
Set the type of Line-Ending that's used to mark the end of a callout - an arrow, circle or similar. The list of valid endings is the same as those for theAnnotationShape
class. This method will only work if a callout is set, ensure you callsetCallout(float[])
first when creating a text callout!- See Also:
Since 2.11.7
-
getCalloutEnding
public java.lang.String getCalloutEnding()
Get the type of Line-Ending, as set bysetCalloutEnding(java.lang.String)
-
getCallout
public float[] getCallout()
Get the callout points, as set bysetCallout(float[])
- Since:
- 2.11.7
-
getContentRectangle
public float[] getContentRectangle()
Return the rectangle of the content of this annotation. If a callout is specified this will be the rectangle of the box itself, as opposed to the rectangle of the entire annotation including the callout arrow. If no callout is in place the return value is identical toPDFAnnotation.getRectangle()
- Since:
- 2.11.7
-
setContentRectangle
public void setContentRectangle(float x1, float y1, float x2, float y2)
Set the rectangle of the content of this annotation. If a callout is specified this will be the rectangle of the box itself, as opposed to the rectangle of the entire annotation including the callout arrow. If no callout is in place this method is identical toPDFAnnotation.setRectangle(float, float, float, float)
- Since:
- 2.11.7
-
rebuild
public void rebuild()
Description copied from class:PDFAnnotation
Rebuild the annotation's appearance. This will be done automatically when required, usually just before saving the PDF or rasterizing it to a bitmap. However this method can be called explicitly if necessary, usually to ensure the rebuild (which may fire aPropertyChangeEvent
) is run on a specific thread.- Overrides:
rebuild
in classPDFAnnotation
-
toString
public java.lang.String toString()
-
putLiteral
public void putLiteral(java.lang.String key, java.lang.String tokens)
Put a literal token sequnce. For debugging- Parameters:
key
- the keytokens
- the token sequence, eg "true" or "/foo" or "[/Foo/Bar]". No refs, just direct objects.
-
clone
protected java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
-