public class TextFlow extends Object implements TextSequence, WidthRespecting
respects a given
width by word wrapping the text. The text may contain line breaks ('\n').markup. The following raw text
Markup supports *bold*, _italic_, and *even _mixed* markup_.is rendered like this:
Markup supports bold, italic, and even mixed markup.Use backslash to escape special characters '*', '_' and '\' itself:
Escape \* with \\\* and \_ with \\\_ in markup.is rendered like this:
Escape * with \* and _ with \_ in markup.
| Modifier and Type | Field and Description |
|---|---|
static float |
DEFAULT_LINE_SPACING |
| Constructor and Description |
|---|
TextFlow() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(TextFragment fragment)
Adds a text fragment to this flow.
|
void |
add(TextSequence sequence)
Adds a text sequence to this flow.
|
void |
addMarkup(String markup,
float fontSize,
BaseFont baseFont)
Adds some markup to the text flow.
|
void |
addMarkup(String markup,
float fontSize,
org.apache.pdfbox.pdmodel.font.PDFont plainFont,
org.apache.pdfbox.pdmodel.font.PDFont boldFont,
org.apache.pdfbox.pdmodel.font.PDFont italicFont,
org.apache.pdfbox.pdmodel.font.PDFont boldItalicFont)
Adds some markup to the text flow.
|
void |
addText(String text,
float fontSize,
org.apache.pdfbox.pdmodel.font.PDFont font)
Adds some text associated with the font to draw.
|
protected TextFlow |
createInstance() |
void |
drawText(org.apache.pdfbox.pdmodel.PDPageContentStream contentStream,
Position upperLeft,
Alignment alignment,
DrawListener drawListener)
Draws the text of the (PdfBox-) cursor position.
|
void |
drawTextRightAligned(org.apache.pdfbox.pdmodel.PDPageContentStream contentStream,
Position endOfFirstLine,
DrawListener drawListener) |
float |
getHeight() |
TextFragment |
getLast() |
float |
getLineSpacing() |
float |
getMaxWidth() |
float |
getWidth() |
boolean |
isApplyLineSpacingToFirstLine()
Indicates if the line spacing should be applied to the first line.
|
boolean |
isEmpty() |
Iterator<TextFragment> |
iterator() |
TextFragment |
removeLast()
Removes the last added fragment.
|
TextFlow |
removeLeadingEmptyLines() |
void |
setApplyLineSpacingToFirstLine(boolean applyLineSpacingToFirstLine)
Sets the indicator whether to apply line spacing to the first line.
|
void |
setLineSpacing(float lineSpacing)
Sets the factor multiplied with the height to calculate the line spacing.
|
void |
setMaxWidth(float maxWidth)
Sets the max width to respect.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static final float DEFAULT_LINE_SPACING
public void addText(String text, float fontSize, org.apache.pdfbox.pdmodel.font.PDFont font) throws IOException
text - the text to add.fontSize - the size of the font.font - the font to use to draw the text.IOException - by PDFBoxpublic void addMarkup(String markup, float fontSize, BaseFont baseFont) throws IOException
markup - the markup to add.fontSize - the font size to use.baseFont - the base font describing the bundle of
plain/blold/italic/bold-italic fonts.IOException - by PDFBoxpublic void addMarkup(String markup, float fontSize, org.apache.pdfbox.pdmodel.font.PDFont plainFont, org.apache.pdfbox.pdmodel.font.PDFont boldFont, org.apache.pdfbox.pdmodel.font.PDFont italicFont, org.apache.pdfbox.pdmodel.font.PDFont boldItalicFont) throws IOException
markup - the markup to add.fontSize - the font size to use.plainFont - the plain font to use.boldFont - the bold font to use.italicFont - the italic font to use.boldItalicFont - the bold-italic font to use.IOException - by PDFBoxpublic void add(TextSequence sequence)
sequence - the sequence to add.public void add(TextFragment fragment)
fragment - the fragment to add.public TextFragment removeLast()
public TextFragment getLast()
public boolean isEmpty()
true if this flow does not contain any fragments.public Iterator<TextFragment> iterator()
iterator in interface Iterable<TextFragment>public float getMaxWidth()
getMaxWidth in interface WidthRespectingpublic void setMaxWidth(float maxWidth)
WidthRespectingsetMaxWidth in interface WidthRespectingmaxWidth - the maximum width.public float getLineSpacing()
public void setLineSpacing(float lineSpacing)
lineSpacing - the line spacing factor.public boolean isApplyLineSpacingToFirstLine()
false. Default is true.true if the line spacing should be applied to the
first line.public void setApplyLineSpacingToFirstLine(boolean applyLineSpacingToFirstLine)
applyLineSpacingToFirstLine - true if the line spacing should be applied to the
first line.isApplyLineSpacingToFirstLine()public float getWidth()
throws IOException
getWidth in interface AreaIOException - by pdfboxpublic float getHeight()
throws IOException
getHeight in interface AreaIOException - by pdfboxpublic void drawText(org.apache.pdfbox.pdmodel.PDPageContentStream contentStream,
Position upperLeft,
Alignment alignment,
DrawListener drawListener)
throws IOException
DrawableTextdrawText in interface DrawableTextcontentStream - the content stream used to render.upperLeft - the upper left position to draw to.alignment - the text alignment.drawListener - the listener to
notify on drawn objects.IOException - by pdfbox.public void drawTextRightAligned(org.apache.pdfbox.pdmodel.PDPageContentStream contentStream,
Position endOfFirstLine,
DrawListener drawListener)
throws IOException
IOExceptionpublic TextFlow removeLeadingEmptyLines() throws IOException
NewLines are removed.IOException - by pdfbox.protected TextFlow createInstance()
Copyright © 2022. All rights reserved.