com.aspose.pdf

Interfaces

Classes

Enums

Exceptions

com.aspose.pdf

Class TextBuilder



  • public final class TextBuilder
    extends Object

    Appends text object to Pdf page.

    • Constructor Detail

      • TextBuilder

        public TextBuilder(Page page)

        Initializes a new instance of TextBuilder class for the Pdf page.

        Parameters:
        page - Page object.

        The TextBuilder allows to append text objects to Pdf pages.

      • TextBuilder

        public TextBuilder(Page page,
                           BaseOperatorCollection operatorCollection)

        Initializes a new instance of TextBuilder class for the Pdf page.

        Parameters:
        page - Page object.
        operatorCollection - Operator collection.
    • Method Detail

      • getSegmenter

        public com.aspose.pdf.engine.commondata.text.segmenting.TextSegmenter getSegmenter()
        Gets TextSegmenter object
        Returns:
        TextSegmenter object
      • appendParagraph

        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);
         
        Parameters:
        textParagraph - Text paragraph object.
      • appendText

        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);
         
        Parameters:
        textFragment - Text fragment object.
      • appendParagraph

        public void appendParagraph(TextParagraph textParagraph,
                                    int rotation)

        Appends paragraph with rotation

        Parameters:
        textParagraph - TextParagraph object
        rotation - int value