public final class TextBuilder extends Object
Appends text object to Pdf page.
| Constructor and Description |
|---|
TextBuilder(Page page)
Initializes a new instance of
TextBuilder class for the Pdf page. |
TextBuilder(Page page,
BaseOperatorCollection operatorCollection)
Initializes a new instance of
TextBuilder class for the Pdf page. |
| Modifier and Type | Method and Description |
|---|---|
void |
appendParagraph(TextParagraph textParagraph)
Appends text paragraph to Pdf page.
|
void |
appendParagraph(TextParagraph textParagraph,
int rotation)
Appends paragraph with rotation
|
void |
appendText(List<TextFragment> textFragments)
Appends list of text fragments to Pdf page.
|
void |
appendText(TextFragment textFragment)
Appends text fragment to Pdf page
|
com.aspose.pdf.engine.commondata.text.segmenting.TextSegmenter |
getSegmenter()
Gets TextSegmenter object
|
public TextBuilder(Page page)
Initializes a new instance of TextBuilder class for the Pdf page.
page - Page object.
The TextBuilder allows to append text objects to Pdf pages.
public TextBuilder(Page page, BaseOperatorCollection operatorCollection)
Initializes a new instance of TextBuilder class for the Pdf page.
page - Page object.operatorCollection - Operator collection.public com.aspose.pdf.engine.commondata.text.segmenting.TextSegmenter getSegmenter()
public void appendParagraph(TextParagraph textParagraph)
Appends text paragraph to Pdf page.
The example demonstrates how to create text paragraph object and append it to the Pdf page.
Document doc = new Document(inFile);
Page page = (Page)doc.getPages().get(1);
// create text paragraph
TextParagraph paragraph = new TextParagraph();
// set the paragraph rectangle
paragraph.setRectangle ( new Rectangle(100, 600, 200, 700));
// set word wrapping options
paragraph.getFormattingOptions().setWrapMode ( TextFormattingOptions.WordWrapMode.ByWords);
// append string lines
paragraph.appendLine("the quick brown fox jumps over the lazy dog");
paragraph.appendLine("line2");
paragraph.appendLine("line3");
// append the paragraph to the Pdf page with the TextBuilder
TextBuilder textBuilder = new TextBuilder(page);
textBuilder.appendParagraph(paragraph);
// save Pdf document
doc.save(outFile);
textParagraph - Text paragraph object.public void appendText(TextFragment textFragment)
Appends text fragment to Pdf page
The example demonstrates how to create text fragment object, customize it's text segments and append it to the Pdf page.
Document doc = new Document(inFile);
Page page = (Page)doc.getPages().get(1);
// create text fragment
TextFragment tf = new TextFragment("main text");
tf.Position = new Position(100, 600);
// set it's text properties
tf.getTextState().setFontSize ( 5);
tf.getTextState().setFont ( FontRepository.FindFont("TimesNewRoman"));
tf.getTextState().setBackgroundColor ( Color.GREY);
tf.getTextState().setForegroundColor ( Color.Red);
// add one more segment to text fragment's Segments collection
TextSegment segment2 = new TextSegment();
segment2.setText ( "another segment");
tf.getSegments.add(segment2);
// create TextBuilder object
TextBuilder builder = new TextBuilder(page);
// append the text fragment to the Pdf page
builder.appendText(tf);
//save document
doc.save(outFile);
textFragment - Text fragment object.public final void appendText(List<TextFragment> textFragments)
textFragments - Collection of text fragmentspublic void appendParagraph(TextParagraph textParagraph, int rotation)
Appends paragraph with rotation
textParagraph - TextParagraph objectrotation - int valueCopyright © 2025 Aspose. All Rights Reserved.