com.aspose.words

Class DocumentBuilder

  • java.lang.Object
    • com.aspose.words.DocumentBuilder
public class DocumentBuilder 
extends java.lang.Object

Provides methods to insert text, images and other content, specify font, paragraph and section formatting.

DocumentBuilder makes the process of building a Document easier. Document is a composite object consisting of a tree of nodes and while inserting content nodes directly into the tree is possible, it requires good understanding of the tree structure. DocumentBuilder is a "facade" for the complex structure of Document and allows to insert content and formatting quickly and easily.

Create a DocumentBuilder and associate it with a Document.

The DocumentBuilder has an internal cursor where the text will be inserted when you call write(java.lang.String), writeln(java.lang.String), insertBreak(int) and other methods. You can navigate the DocumentBuilder cursor to a different location in a document using various MoveToXXX methods.

Use the Font property to specify character formatting that will apply to all text inserted from the current position in the document onwards.

Use the ParagraphFormat property to specify paragraph formatting for the current and all paragraphs that will be inserted.

Use the PageSetup property to specify page and section properties for the current section and all section that will be inserted.

Use the CellFormat and RowFormat properties to specify formatting properties for table cells and rows. User the insertCell() and endRow() methods to build a table.

Note that Font, ParagraphFormat and PageSetup properties are updated whenever you navigate to a different place in the document to reflect formatting properties available at the new location.

Example:

Adds some text into the document and encloses the text in a bookmark using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();

builder.startBookmark("MyBookmark");
builder.writeln("Text inside a bookmark.");
builder.endBookmark("MyBookmark");

Example:

Inserts HTML into a document. The formatting specified in the HTML is applied.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.insertHtml("<P align='right'>Paragraph right</P>" + "<b>Implicit paragraph left</b>" + "<div align='center'>Div center</div>" + "<h1 align='left'>Heading 1 left.</h1>");

doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertHtml.doc");

Example:

Shows how to create a simple table using DocumentBuilder with default formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// We call this method to start building the table.
builder.startTable();
builder.insertCell();
builder.write("Row 1, Cell 1 Content.");

// Build the second cell
builder.insertCell();
builder.write("Row 1, Cell 2 Content.");
// Call the following method to end the row and start a new row.
builder.endRow();

// Build the first cell of the second row.
builder.insertCell();
builder.write("Row 2, Cell 1 Content");

// Build the second cell.
builder.insertCell();
builder.write("Row 2, Cell 2 Content.");
builder.endRow();

// Signal that we have finished building the table.
builder.endTable();

// Save the document to disk.
doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateSimpleTable.doc");

Example:

Shows how to create a formatted table using DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();

// Make the header row.
builder.insertCell();

// Set the left indent for the table. Table wide formatting must be applied after
// at least one row is present in the table.
table.setLeftIndent(20.0);

// Set height and define the height rule for the header row.
builder.getRowFormat().setHeight(40.0);
builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);

// Some special features for the header row.
builder.getCellFormat().getShading().setBackgroundPatternColor(new Color(198, 217, 241));
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.getFont().setSize(16);
builder.getFont().setName("Arial");
builder.getFont().setBold(true);

builder.getCellFormat().setWidth(100.0);
builder.write("Header Row,\n Cell 1");

// We don't need to specify the width of this cell because it's inherited from the previous cell.
builder.insertCell();
builder.write("Header Row,\n Cell 2");

builder.insertCell();
builder.getCellFormat().setWidth(200.0);
builder.write("Header Row,\n Cell 3");
builder.endRow();

// Set features for the other rows and cells.
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
builder.getCellFormat().setWidth(100.0);
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);

// Reset height and define a different height rule for table body
builder.getRowFormat().setHeight(30.0);
builder.getRowFormat().setHeightRule(HeightRule.AUTO);
builder.insertCell();
// Reset font formatting.
builder.getFont().setSize(12);
builder.getFont().setBold(false);

// Build the other cells.
builder.write("Row 1, Cell 1 Content");
builder.insertCell();
builder.write("Row 1, Cell 2 Content");

builder.insertCell();
builder.getCellFormat().setWidth(200.0);
builder.write("Row 1, Cell 3 Content");
builder.endRow();

builder.insertCell();
builder.getCellFormat().setWidth(100.0);
builder.write("Row 2, Cell 1 Content");

builder.insertCell();
builder.write("Row 2, Cell 2 Content");

builder.insertCell();
builder.getCellFormat().setWidth(200.0);
builder.write("Row 2, Cell 3 Content.");
builder.endRow();
builder.endTable();

doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateFormattedTable.doc");

Constructor Summary
DocumentBuilder()
Initializes a new instance of this class.
DocumentBuilder(Document doc)
Initializes a new instance of this class.
 
Property Getters/Setters Summary
booleangetBold()
void
setBold(booleanvalue)
           True if the font is formatted as bold.
CellFormatgetCellFormat()
Returns an object that represents current table cell formatting properties.
NodegetCurrentNode()
Gets the node that is currently selected in this DocumentBuilder.
ParagraphgetCurrentParagraph()
Gets the paragraph that is currently selected in this DocumentBuilder.
SectiongetCurrentSection()
Gets the section that is currently selected in this DocumentBuilder.
StorygetCurrentStory()
Gets the story that is currently selected in this DocumentBuilder.
DocumentgetDocument()
void
           Gets or sets the Document object that this object is attached to.
FontgetFont()
Returns an object that represents current font formatting properties.
booleanisAtEndOfParagraph()
Returns true if the cursor is at the end of the current paragraph.
booleanisAtStartOfParagraph()
Returns true if the cursor is at the beginning of the current paragraph (no text before the cursor).
booleangetItalic()
void
setItalic(booleanvalue)
           True if the font is formatted as italic.
ListFormatgetListFormat()
Returns an object that represents current list formatting properties.
PageSetupgetPageSetup()
Returns an object that represents current page setup and section properties.
ParagraphFormatgetParagraphFormat()
Returns an object that represents current paragraph formatting properties.
RowFormatgetRowFormat()
Returns an object that represents current table row formatting properties.
intgetUnderline()
void
setUnderline(intvalue)
           Gets/sets underline type for the current font. The value of the property is Underline integer constant.
 
Method Summary
RowdeleteRow(int tableIndex, int rowIndex)
Deletes a row from a table.
BookmarkEndendBookmark(java.lang.String bookmarkName)
Marks the current position in the document as a bookmark end.
EditableRangeEndendEditableRange()
Marks the current position in the document as an editable range end.
EditableRangeEndendEditableRange(EditableRangeStart start)
Marks the current position in the document as an editable range end.
RowendRow()
Ends a table row in the document.
TableendTable()
Ends a table in the document.
voidinsertBreak(int breakType)
Inserts a break of the specified type into the document.
CellinsertCell()
Inserts a table cell into the document.
ShapeinsertChart(int chartType, double width, double height)
Inserts an chart object into the document and scales it to the specified size.
ShapeinsertChart(int chartType, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
Inserts an chart object into the document and scales it to the specified size.
FormFieldinsertCheckBox(java.lang.String name, boolean defaultValue, boolean checkedValue, int size)
Inserts a checkbox form field at the current position.
FormFieldinsertCheckBox(java.lang.String name, boolean checkedValue, int size)
Inserts a checkbox form field at the current position.
FormFieldinsertComboBox(java.lang.String name, java.lang.String[] items, int selectedIndex)
Inserts a combobox form field at the current position.
NodeinsertDocument(Document srcDoc, int importFormatMode)
Inserts content of the document into the current position of DocumentBuilder's cursor.
FieldinsertField(int fieldType, boolean updateField)
Inserts a Word field into a document and optionally updates the field result.
FieldinsertField(java.lang.String fieldCode)
Inserts a Word field into a document and updates the field result.
FieldinsertField(java.lang.String fieldCode, java.lang.String fieldValue)
Inserts a Word field into a document without updating the field result.
FootnoteinsertFootnote(int footnoteType, java.lang.String footnoteText)
Inserts a footnote or endnote into the document.
FootnoteinsertFootnote(int footnoteType, java.lang.String footnoteText, java.lang.String referenceMark)
Inserts a footnote or endnote into the document.
voidinsertHorizontalRule()
Inserts a horizontal rule shape into the document.
voidinsertHtml(java.lang.String html)
Inserts an HTML string into the document.
voidinsertHtml(java.lang.String html, boolean useBuilderFormatting)
Inserts an HTML string into the document.
FieldinsertHyperlink(java.lang.String displayText, java.lang.String urlOrBookmark, boolean isBookmark)
Inserts a hyperlink into the document.
ShapeinsertImage(byte[] imageBytes)
Inserts an image from a byte array into the document. The image is inserted inline and at 100% scale.
ShapeinsertImage(byte[] imageBytes, double width, double height)
Inserts an inline image from a byte array into the document and scales it to the specified size.
ShapeinsertImage(byte[] imageBytes, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
Inserts an image from a byte array at the specified position and size.
ShapeinsertImage(java.awt.image.BufferedImage image)
Inserts an image from a java.awt.image.BufferedImage object into the document. The image is inserted inline and at 100% scale.
ShapeinsertImage(java.awt.image.BufferedImage image, double width, double height)
Inserts an inline image from a java.awt.image.BufferedImage object into the document and scales it to the specified size.
ShapeinsertImage(java.awt.image.BufferedImage image, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
Inserts an image from a java.awt.image.BufferedImage object at the specified position and size.
ShapeinsertImage(java.io.InputStream stream)
Inserts an image from a stream into the document. The image is inserted inline and at 100% scale.
ShapeinsertImage(java.io.InputStream stream, double width, double height)
Inserts an inline image from a stream into the document and scales it to the specified size.
ShapeinsertImage(java.io.InputStream stream, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
Inserts an image from a stream at the specified position and size.
ShapeinsertImage(java.lang.String fileName)
Inserts an image from a file or URL into the document. The image is inserted inline and at 100% scale.
ShapeinsertImage(java.lang.String fileName, double width, double height)
Inserts an inline image from a file or URL into the document and scales it to the specified size.
ShapeinsertImage(java.lang.String fileName, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
Inserts an image from a file or URL at the specified position and size.
voidinsertNode(Node node)
Inserts a text level node inside the current paragraph before the cursor.
ShapeinsertOleObject(java.lang.String fileName, boolean isLinked, boolean asIcon, java.awt.image.BufferedImage presentation)
Inserts an embedded or linked OLE object from a file into the document. Detects OLE object type using file extension.
ShapeinsertOleObject(java.lang.String fileName, java.lang.String progId, boolean isLinked, boolean asIcon, java.awt.image.BufferedImage presentation)
Inserts an embedded or linked OLE object from a file into the document. Detects OLE object type using given progID parameter.
ShapeinsertOnlineVideo(java.lang.String videoUrl, double width, double height)
Inserts an online video object into the document and scales it to the specified size.
ShapeinsertOnlineVideo(java.lang.String videoUrl, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
Inserts an online video object into the document and scales it to the specified size.
ShapeinsertOnlineVideo(java.lang.String videoUrl, java.lang.String videoEmbedCode, byte[] thumbnailImageBytes, double width, double height)
Inserts an online video object into the document and scales it to the specified size.
ShapeinsertOnlineVideo(java.lang.String videoUrl, java.lang.String videoEmbedCode, byte[] thumbnailImageBytes, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
Inserts an online video object into the document and scales it to the specified size.
ParagraphinsertParagraph()
Inserts a paragraph break into the document.
ShapeinsertShape(int shapeType, double width, double height)
Inserts inline shape with specified type and size.
ShapeinsertShape(int shapeType, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
Inserts free-floating shape with specified position, size and text wrap type.
ShapeinsertSignatureLine(SignatureLineOptions signatureLineOptions)
Inserts a signature line at the current position.
ShapeinsertSignatureLine(SignatureLineOptions signatureLineOptions, int horzPos, double left, int vertPos, double top, int wrapType)
Inserts a signature line at the specified position.
voidinsertStyleSeparator()
Inserts style separator into the document.
FieldinsertTableOfContents(java.lang.String switches)
Inserts a TOC (table of contents) field into the document.
FormFieldinsertTextInput(java.lang.String name, int type, java.lang.String format, java.lang.String fieldValue, int maxLength)
Inserts a text form field at the current position.
voidmoveTo(Node node)
Moves the cursor to an inline node or to the end of a paragraph.
booleanmoveToBookmark(java.lang.String bookmarkName)
Moves the cursor to a bookmark.
booleanmoveToBookmark(java.lang.String bookmarkName, boolean isStart, boolean isAfter)
Moves the cursor to a bookmark with greater precision.
voidmoveToCell(int tableIndex, int rowIndex, int columnIndex, int characterIndex)
Moves the cursor to a table cell in the current section.
voidmoveToDocumentEnd()
Moves the cursor to the end of the document.
voidmoveToDocumentStart()
Moves the cursor to the beginning of the document.
voidmoveToField(Field field, boolean isAfter)
Moves the cursor to a field in the document.
voidmoveToHeaderFooter(int headerFooterType)
Moves the cursor to the beginning of a header or footer in the current section.
booleanmoveToMergeField(java.lang.String fieldName)
Moves the cursor to a position just beyond the specified merge field and removes the merge field.
booleanmoveToMergeField(java.lang.String fieldName, boolean isAfter, boolean isDeleteField)
Moves the merge field to the specified merge field.
voidmoveToParagraph(int paragraphIndex, int characterIndex)
Moves the cursor to a paragraph in the current section.
voidmoveToSection(int sectionIndex)
Moves the cursor to the beginning of the body in a specified section.
voidpopFont()
Retrieves character formatting previously saved on the stack.
voidpushFont()
Saves current character formatting onto the stack.
BookmarkStartstartBookmark(java.lang.String bookmarkName)
Marks the current position in the document as a bookmark start.
EditableRangeStartstartEditableRange()
Marks the current position in the document as an editable range start.
TablestartTable()
Starts a table in the document.
voidwrite(java.lang.String text)
Inserts a string into the document at the current insert position.
voidwriteln()
Inserts a paragraph break into the document.
voidwriteln(java.lang.String text)
Inserts a string and a paragraph break into the document.
 

    • Constructor Detail

      • DocumentBuilder

        public DocumentBuilder()
                        throws java.lang.Exception
        Initializes a new instance of this class. Creates a new DocumentBuilder object and attaches it to a new Document object.

        Example:

        Inserts formatted text using DocumentBuilder.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Specify font formatting before adding text.
        Font font = builder.getFont();
        font.setSize(16);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Arial");
        font.setUnderline(Underline.DASH);
        
        builder.write("Sample text.");
      • DocumentBuilder

        public DocumentBuilder(Document doc)
        Initializes a new instance of this class. Creates a new DocumentBuilder object, attaches to the specified Document object. The cursor is positioned at the beginning of the document.
        Parameters:
        doc - The Document object to attach to.

        Example:

        Demonstrates how to insert a Table of contents (TOC) into a document using heading styles as entries.
        // Use a blank document
        Document doc = new Document();
        // Create a document builder to insert content with into document.
        DocumentBuilder builder = new DocumentBuilder(doc);
        // Insert a table of contents at the beginning of the document.
        builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
        // Start the actual document content on the second page.
        builder.insertBreak(BreakType.PAGE_BREAK);
        // Build a document with complex structure by applying different heading styles thus creating TOC entries.
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        
        builder.writeln("Heading 1");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 1.1");
        builder.writeln("Heading 1.2");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        
        builder.writeln("Heading 2");
        builder.writeln("Heading 3");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 3.1");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_3);
        
        builder.writeln("Heading 3.1.1");
        builder.writeln("Heading 3.1.2");
        builder.writeln("Heading 3.1.3");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 3.2");
        builder.writeln("Heading 3.3");
        
        // Call the method below to update the TOC.
        doc.updateFields();

        Example:

        Creates headers and footers in a document using DocumentBuilder.
        // Create a blank document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want headers and footers different for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header First");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header Even");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header Odd");
        
        // Create three pages in the document.
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.HeadersAndFooters.doc");
    • Property Getters/Setters Detail

      • getBold/setBold

        public boolean getBold() / public void setBold(boolean value)
        
        True if the font is formatted as bold.

        Example:

        Fills document merge fields with some data.
        Document doc = new Document(getMyDir() + "DocumentBuilder.FillingDocument.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.moveToMergeField("TeamLeaderName");
        builder.setBold(true);
        builder.writeln("Roman Korchagin");
        
        builder.moveToMergeField("SoftwareDeveloper1Name");
        builder.setItalic(true);
        builder.writeln("Dmitry Vorobyev");
        
        builder.moveToMergeField("SoftwareDeveloper2Name");
        builder.setItalic(true);
        builder.writeln("Vladimir Averkin");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.FillingDocument.doc");
      • getCellFormat

        public CellFormat getCellFormat()
        
        Returns an object that represents current table cell formatting properties.

        Example:

        Shows how to create a table that contains a single formatted cell.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        builder.insertCell();
        
        // Set the cell formatting
        CellFormat cellFormat = builder.getCellFormat();
        cellFormat.setWidth(250);
        cellFormat.setLeftPadding(30);
        cellFormat.setRightPadding(30);
        cellFormat.setTopPadding(30);
        cellFormat.setBottomPadding(30);
        
        builder.writeln("I'm a wonderful formatted cell.");
        
        builder.endRow();
        builder.endTable();

        Example:

        Shows how to build a formatted table that contains 2 rows and 2 columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Insert a cell
        builder.insertCell();
        // Use fixed column widths.
        table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
        
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("This is row 1 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.write("This is row 1 cell 2");
        
        builder.endRow();
        
        // Insert a cell
        builder.insertCell();
        
        // Apply new row formatting
        builder.getRowFormat().setHeight(100);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.writeln("This is row 2 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.writeln("This is row 2 cell 2");
        
        builder.endRow();
        
        builder.endTable();
      • getCurrentNode

        public Node getCurrentNode()
        
        Gets the node that is currently selected in this DocumentBuilder.

        CurrentNode is a cursor of DocumentBuilder and points to a Node that is a direct child of a Paragraph. Any insert operations you perform using DocumentBuilder will insert before the CurrentNode.

        When the current paragraph is empty or the cursor is positioned just before the end of the paragraph, CurrentNode returns null.

        Example:

        Shows how to move between nodes and manipulate current ones.
        Document doc = new Document(getMyDir() + "DocumentBuilder.WorkingWithNodes.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Move to a bookmark and delete the parent paragraph.
        builder.moveToBookmark("ParaToDelete");
        builder.getCurrentParagraph().remove();
        
        FindReplaceOptions options = new FindReplaceOptions();
        options.setMatchCase(false);
        options.setFindWholeWordsOnly(true);
        
        // Move to a particular paragraph's run and replace all occurrences of "bad" with "good" within this run.
        builder.moveTo(doc.getLastSection().getBody().getParagraphs().get(0).getRuns().get(0));
        builder.getCurrentNode().getRange().replace("bad", "good", options);
        
        // Mark the beginning of the document.
        builder.moveToDocumentStart();
        builder.writeln("Start of document.");
        
        // Mark the ending of the document.
        builder.moveToDocumentEnd();
        builder.writeln("End of document.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.WorkingWithNodes.doc");
        See Also:
        CurrentParagraph
      • getCurrentParagraph

        public Paragraph getCurrentParagraph()
        
        Gets the paragraph that is currently selected in this DocumentBuilder. CurrentNode

        Example:

        Shows how to move between nodes and manipulate current ones.
        Document doc = new Document(getMyDir() + "DocumentBuilder.WorkingWithNodes.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Move to a bookmark and delete the parent paragraph.
        builder.moveToBookmark("ParaToDelete");
        builder.getCurrentParagraph().remove();
        
        FindReplaceOptions options = new FindReplaceOptions();
        options.setMatchCase(false);
        options.setFindWholeWordsOnly(true);
        
        // Move to a particular paragraph's run and replace all occurrences of "bad" with "good" within this run.
        builder.moveTo(doc.getLastSection().getBody().getParagraphs().get(0).getRuns().get(0));
        builder.getCurrentNode().getRange().replace("bad", "good", options);
        
        // Mark the beginning of the document.
        builder.moveToDocumentStart();
        builder.writeln("Start of document.");
        
        // Mark the ending of the document.
        builder.moveToDocumentEnd();
        builder.writeln("End of document.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.WorkingWithNodes.doc");
      • getCurrentSection

        public Section getCurrentSection()
        
        Gets the section that is currently selected in this DocumentBuilder.

        Example:

        Shows how to insert a floating image and specify its position and size.
        // This creates a builder and also an empty document inside the builder.
        DocumentBuilder builder = new DocumentBuilder();
        
        // By default, the image is inline.
        Shape shape = builder.insertImage(getMyDir() + "\\Images\\Hammer.wmf");
        
        // Make the image float, put it behind text and center on the page.
        shape.setWrapType(WrapType.NONE);
        
        // Make position relative to the page.
        shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        
        // Make the shape occupy a band 50 points high at the very top of the page.
        shape.setLeft(0);
        shape.setTop(0);
        shape.setWidth(builder.getCurrentSection().getPageSetup().getPageWidth());
        shape.setHeight(50);
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFloatingPositionSize.doc");
      • getCurrentStory

        public Story getCurrentStory()
        
        Gets the story that is currently selected in this DocumentBuilder.
      • getDocument/setDocument

        public Document getDocument() / public void setDocument(Document value)
        
        Gets or sets the Document object that this object is attached to.

        Example:

        Shows how to insert sections using DocumentBuilder, specify page setup for a section and reset page setup to defaults.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Modify the first section in the document.
        builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
        builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
        builder.writeln("Section 1, landscape oriented and text vertically centered.");
        
        // Start a new section and reset its formatting to defaults.
        builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
        builder.getPageSetup().clearFormatting();
        builder.writeln("Section 2, back to default Letter paper size, portrait orientation and top alignment.");
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\PageSetup.ClearFormatting.doc");
      • getFont

        public Font getFont()
        
        Returns an object that represents current font formatting properties.

        Use Font to access and modify font formatting properties.

        Specify font formatting before inserting text.

        Example:

        Inserts a String surrounded by a border into a document.
        DocumentBuilder builder = new DocumentBuilder();
        
        builder.getFont().getBorder().setColor(Color.GREEN);
        builder.getFont().getBorder().setLineWidth(2.5);
        builder.getFont().getBorder().setLineStyle(LineStyle.DASH_DOT_STROKER);
        
        builder.write("run of text in a green border");

        Example:

        Shows how to create a formatted table using DocumentBuilder
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Make the header row.
        builder.insertCell();
        
        // Set the left indent for the table. Table wide formatting must be applied after
        // at least one row is present in the table.
        table.setLeftIndent(20.0);
        
        // Set height and define the height rule for the header row.
        builder.getRowFormat().setHeight(40.0);
        builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);
        
        // Some special features for the header row.
        builder.getCellFormat().getShading().setBackgroundPatternColor(new Color(198, 217, 241));
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        builder.getFont().setSize(16);
        builder.getFont().setName("Arial");
        builder.getFont().setBold(true);
        
        builder.getCellFormat().setWidth(100.0);
        builder.write("Header Row,\n Cell 1");
        
        // We don't need to specify the width of this cell because it's inherited from the previous cell.
        builder.insertCell();
        builder.write("Header Row,\n Cell 2");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Header Row,\n Cell 3");
        builder.endRow();
        
        // Set features for the other rows and cells.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
        builder.getCellFormat().setWidth(100.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        
        // Reset height and define a different height rule for table body
        builder.getRowFormat().setHeight(30.0);
        builder.getRowFormat().setHeightRule(HeightRule.AUTO);
        builder.insertCell();
        // Reset font formatting.
        builder.getFont().setSize(12);
        builder.getFont().setBold(false);
        
        // Build the other cells.
        builder.write("Row 1, Cell 1 Content");
        builder.insertCell();
        builder.write("Row 1, Cell 2 Content");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Row 1, Cell 3 Content");
        builder.endRow();
        
        builder.insertCell();
        builder.getCellFormat().setWidth(100.0);
        builder.write("Row 2, Cell 1 Content");
        
        builder.insertCell();
        builder.write("Row 2, Cell 2 Content");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Row 2, Cell 3 Content.");
        builder.endRow();
        builder.endTable();
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateFormattedTable.doc");
      • isAtEndOfParagraph

        public boolean isAtEndOfParagraph()
        
        Returns true if the cursor is at the end of the current paragraph.
      • isAtStartOfParagraph

        public boolean isAtStartOfParagraph()
        
        Returns true if the cursor is at the beginning of the current paragraph (no text before the cursor).
      • getItalic/setItalic

        public boolean getItalic() / public void setItalic(boolean value)
        
        True if the font is formatted as italic.

        Example:

        Fills document merge fields with some data.
        Document doc = new Document(getMyDir() + "DocumentBuilder.FillingDocument.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.moveToMergeField("TeamLeaderName");
        builder.setBold(true);
        builder.writeln("Roman Korchagin");
        
        builder.moveToMergeField("SoftwareDeveloper1Name");
        builder.setItalic(true);
        builder.writeln("Dmitry Vorobyev");
        
        builder.moveToMergeField("SoftwareDeveloper2Name");
        builder.setItalic(true);
        builder.writeln("Vladimir Averkin");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.FillingDocument.doc");
      • getListFormat

        public ListFormat getListFormat()
        
        Returns an object that represents current list formatting properties.

        Example:

        Shows how to apply default bulleted or numbered list formatting to paragraphs when using DocumentBuilder.
        DocumentBuilder builder = new DocumentBuilder();
        
        builder.writeln("Aspose.Words allows:");
        builder.writeln();
        
        // Start a numbered list with default formatting.
        builder.getListFormat().applyNumberDefault();
        builder.writeln("Opening documents from different formats:");
        
        // Go to second list level, add more text.
        builder.getListFormat().listIndent();
        builder.writeln("DOC");
        builder.writeln("PDF");
        builder.writeln("HTML");
        
        // Outdent to the first list level.
        builder.getListFormat().listOutdent();
        builder.writeln("Processing documents");
        builder.writeln("Saving documents in different formats:");
        
        // Indent the list level again.
        builder.getListFormat().listIndent();
        builder.writeln("DOC");
        builder.writeln("PDF");
        builder.writeln("HTML");
        builder.writeln("MHTML");
        builder.writeln("Plain text");
        
        // Outdent the list level again.
        builder.getListFormat().listOutdent();
        builder.writeln("Doing many other things!");
        
        // End the numbered list.
        builder.getListFormat().removeNumbers();
        builder.writeln();
        
        builder.writeln("Aspose.Words main advantages are:");
        builder.writeln();
        
        // Start a bulleted list with default formatting.
        builder.getListFormat().applyBulletDefault();
        builder.writeln("Great performance");
        builder.writeln("High reliability");
        builder.writeln("Quality code and working");
        builder.writeln("Wide variety of features");
        builder.writeln("Easy to understand API");
        
        // End the bulleted list.
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Lists.ApplyDefaultBulletsAndNumbers.doc");
      • getPageSetup

        public PageSetup getPageSetup()
        
        Returns an object that represents current page setup and section properties.

        Example:

        Shows how to insert sections using DocumentBuilder, specify page setup for a section and reset page setup to defaults.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Modify the first section in the document.
        builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
        builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
        builder.writeln("Section 1, landscape oriented and text vertically centered.");
        
        // Start a new section and reset its formatting to defaults.
        builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
        builder.getPageSetup().clearFormatting();
        builder.writeln("Section 2, back to default Letter paper size, portrait orientation and top alignment.");
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\PageSetup.ClearFormatting.doc");
      • getParagraphFormat

        public ParagraphFormat getParagraphFormat()
        
        Returns an object that represents current paragraph formatting properties.

        Example:

        Shows how to create a formatted table using DocumentBuilder
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Make the header row.
        builder.insertCell();
        
        // Set the left indent for the table. Table wide formatting must be applied after
        // at least one row is present in the table.
        table.setLeftIndent(20.0);
        
        // Set height and define the height rule for the header row.
        builder.getRowFormat().setHeight(40.0);
        builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);
        
        // Some special features for the header row.
        builder.getCellFormat().getShading().setBackgroundPatternColor(new Color(198, 217, 241));
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        builder.getFont().setSize(16);
        builder.getFont().setName("Arial");
        builder.getFont().setBold(true);
        
        builder.getCellFormat().setWidth(100.0);
        builder.write("Header Row,\n Cell 1");
        
        // We don't need to specify the width of this cell because it's inherited from the previous cell.
        builder.insertCell();
        builder.write("Header Row,\n Cell 2");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Header Row,\n Cell 3");
        builder.endRow();
        
        // Set features for the other rows and cells.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
        builder.getCellFormat().setWidth(100.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        
        // Reset height and define a different height rule for table body
        builder.getRowFormat().setHeight(30.0);
        builder.getRowFormat().setHeightRule(HeightRule.AUTO);
        builder.insertCell();
        // Reset font formatting.
        builder.getFont().setSize(12);
        builder.getFont().setBold(false);
        
        // Build the other cells.
        builder.write("Row 1, Cell 1 Content");
        builder.insertCell();
        builder.write("Row 1, Cell 2 Content");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Row 1, Cell 3 Content");
        builder.endRow();
        
        builder.insertCell();
        builder.getCellFormat().setWidth(100.0);
        builder.write("Row 2, Cell 1 Content");
        
        builder.insertCell();
        builder.write("Row 2, Cell 2 Content");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Row 2, Cell 3 Content.");
        builder.endRow();
        builder.endTable();
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateFormattedTable.doc");
      • getRowFormat

        public RowFormat getRowFormat()
        
        Returns an object that represents current table row formatting properties.

        Example:

        Shows how to create a table that contains a single cell and apply row formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        
        // Set the row formatting
        RowFormat rowFormat = builder.getRowFormat();
        rowFormat.setHeight(100);
        rowFormat.setHeightRule(HeightRule.EXACTLY);
        // These formatting properties are set on the table and are applied to all rows in the table.
        table.setLeftPadding(30);
        table.setRightPadding(30);
        table.setTopPadding(30);
        table.setBottomPadding(30);
        
        builder.writeln("I'm a wonderful formatted row.");
        
        builder.endRow();
        builder.endTable();

        Example:

        Shows how to build a formatted table that contains 2 rows and 2 columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Insert a cell
        builder.insertCell();
        // Use fixed column widths.
        table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
        
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("This is row 1 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.write("This is row 1 cell 2");
        
        builder.endRow();
        
        // Insert a cell
        builder.insertCell();
        
        // Apply new row formatting
        builder.getRowFormat().setHeight(100);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.writeln("This is row 2 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.writeln("This is row 2 cell 2");
        
        builder.endRow();
        
        builder.endTable();
      • getUnderline/setUnderline

        public int getUnderline() / public void setUnderline(int value)
        
        Gets/sets underline type for the current font. The value of the property is Underline integer constant.
    • Method Detail

      • deleteRow

        public Row deleteRow(int tableIndex, int rowIndex)
        Deletes a row from a table.

        If the cursor is inside the row that is being deleted, the cursor is moved out to the next row or to the next paragraph after the table.

        If you delete a row from a table that contains only one row, the whole table is deleted.

        For the index parameters, when index is greater than or equal to 0, it specifies an index from the beginning with 0 being the first element. When index is less than 0, it specified an index from the end with -1 being the last element.

        Parameters:
        tableIndex - The index of the table.
        rowIndex - The index of the row in the table.
        Returns:
        The row node that was just removed.

        Example:

        Shows how to delete a row from a table.
        Document doc = new Document(getMyDir() + "DocumentBuilder.DocWithTable.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Delete the first row of the first table in the document.
        builder.deleteRow(0, 0);
      • endBookmark

        public BookmarkEnd endBookmark(java.lang.String bookmarkName)
        Marks the current position in the document as a bookmark end.

        Bookmarks in a document can overlap and span any range. To create a valid bookmark you need to call both startBookmark(java.lang.String) and endBookmark(java.lang.String) with the same bookmarkName parameter.

        Badly formed bookmarks or bookmarks with duplicate names will be ignored when the document is saved.

        Parameters:
        bookmarkName - Name of the bookmark.
        Returns:
        The bookmark end node that was just created.

        Example:

        Inserts a hyperlink referencing local bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startBookmark("Bookmark1");
        builder.write("Bookmarked text.");
        builder.endBookmark("Bookmark1");
        
        builder.writeln("Some other text");
        
        // Specify font formatting for the hyperlink.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        
        // Insert hyperlink.
        // Switch \o is used to provide hyperlink tip text.
        builder.insertHyperlink("Hyperlink Text", "Bookmark1\" \\o \"Hyperlink Tip", true);
        
        // Clear hyperlink formatting.
        builder.getFont().clearFormatting();
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertHyperlinkToLocalBookmark.doc");

        Example:

        Adds some text into the document and encloses the text in a bookmark using DocumentBuilder.
        DocumentBuilder builder = new DocumentBuilder();
        
        builder.startBookmark("MyBookmark");
        builder.writeln("Text inside a bookmark.");
        builder.endBookmark("MyBookmark");
      • endEditableRange

        public EditableRangeEnd endEditableRange()
        Marks the current position in the document as an editable range end.

        Editable range in a document can overlap and span any range. To create a valid editable range you need to call both startEditableRange() and endEditableRange() or endEditableRange(com.aspose.words.EditableRangeStart) methods.

        Badly formed editable range will be ignored when the document is saved.

        Returns:
        The editable range end node that was just created.

        Example:

        Shows how to start and end an editable range.
        Document doc = new Document(getMyDir() + "Document.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Start an editable range.
        EditableRangeStart edRange1Start = builder.startEditableRange();
        
        // An EditableRange object is created for the EditableRangeStart that we just made.
        EditableRange editableRange1 = edRange1Start.getEditableRange();
        
        // Put something inside the editable range.
        builder.writeln("Paragraph inside first editable range");
        
        // An editable range is well-formed if it has a start and an end. 
        // Multiple editable ranges can be nested and overlapping. 
        EditableRangeEnd edRange1End = builder.endEditableRange();
        
        // Both the start and end automatically belong to editableRange1.
        System.out.println(editableRange1.getEditableRangeStart().equals(edRange1Start)); // True
        System.out.println(editableRange1.getEditableRangeEnd().equals(edRange1End)); // True
        
        // Explicitly state which EditableRangeStart a new EditableRangeEnd should be paired with.
        EditableRangeStart edRange2Start = builder.startEditableRange();
        builder.writeln("Paragraph inside second editable range");
        EditableRange editableRange2 = edRange2Start.getEditableRange();
        EditableRangeEnd edRange2End = builder.endEditableRange(edRange2Start);
        
        // Both the start and end automatically belong to editableRange2.
        System.out.println(editableRange2.getEditableRangeStart().equals(edRange2Start)); // True
        System.out.println(editableRange2.getEditableRangeEnd().equals(edRange2End)); // True
      • endEditableRange

        public EditableRangeEnd endEditableRange(EditableRangeStart start)
        Marks the current position in the document as an editable range end.

        Use this overload during creating nested editable ranges.

        Editable range in a document can overlap and span any range. To create a valid editable range you need to call both startEditableRange() and endEditableRange() or endEditableRange(com.aspose.words.EditableRangeStart) methods.

        Badly formed editable range will be ignored when the document is saved.

        Parameters:
        start - This editable range start.
        Returns:
        The editable range end node that was just created.

        Example:

        Shows how to start and end an editable range.
        Document doc = new Document(getMyDir() + "Document.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Start an editable range.
        EditableRangeStart edRange1Start = builder.startEditableRange();
        
        // An EditableRange object is created for the EditableRangeStart that we just made.
        EditableRange editableRange1 = edRange1Start.getEditableRange();
        
        // Put something inside the editable range.
        builder.writeln("Paragraph inside first editable range");
        
        // An editable range is well-formed if it has a start and an end. 
        // Multiple editable ranges can be nested and overlapping. 
        EditableRangeEnd edRange1End = builder.endEditableRange();
        
        // Both the start and end automatically belong to editableRange1.
        System.out.println(editableRange1.getEditableRangeStart().equals(edRange1Start)); // True
        System.out.println(editableRange1.getEditableRangeEnd().equals(edRange1End)); // True
        
        // Explicitly state which EditableRangeStart a new EditableRangeEnd should be paired with.
        EditableRangeStart edRange2Start = builder.startEditableRange();
        builder.writeln("Paragraph inside second editable range");
        EditableRange editableRange2 = edRange2Start.getEditableRange();
        EditableRangeEnd edRange2End = builder.endEditableRange(edRange2Start);
        
        // Both the start and end automatically belong to editableRange2.
        System.out.println(editableRange2.getEditableRangeStart().equals(edRange2Start)); // True
        System.out.println(editableRange2.getEditableRangeEnd().equals(edRange2End)); // True
      • endRow

        public Row endRow()
        Ends a table row in the document.

        Call EndRow to end a table row. If you call insertCell() immediately after that, then the table continues on a new row.

        Use the RowFormat property to specify row formatting.

        Returns:
        The row node that was just finished.

        Example:

        Shows how to build a formatted table that contains 2 rows and 2 columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Insert a cell
        builder.insertCell();
        // Use fixed column widths.
        table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
        
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("This is row 1 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.write("This is row 1 cell 2");
        
        builder.endRow();
        
        // Insert a cell
        builder.insertCell();
        
        // Apply new row formatting
        builder.getRowFormat().setHeight(100);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.writeln("This is row 2 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.writeln("This is row 2 cell 2");
        
        builder.endRow();
        
        builder.endTable();

        Example:

        Creates a table with two columns with cells merged vertically in the first column.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
        builder.write("Text in merged cells.");
        
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
        builder.write("Text in one cell");
        builder.endRow();
        
        builder.insertCell();
        // This cell is vertically merged to the cell above and should be empty.
        builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
        
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
        builder.write("Text in another cell");
        builder.endRow();
        builder.endTable();
      • endTable

        public Table endTable()
        Ends a table in the document.

        This method should be called only once after endRow() was called. When called, EndTable moves the cursor out of the current cell to point just after the table.

        Returns:
        The table node that was just finished.

        Example:

        Shows how to build a formatted table that contains 2 rows and 2 columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Insert a cell
        builder.insertCell();
        // Use fixed column widths.
        table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
        
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("This is row 1 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.write("This is row 1 cell 2");
        
        builder.endRow();
        
        // Insert a cell
        builder.insertCell();
        
        // Apply new row formatting
        builder.getRowFormat().setHeight(100);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.writeln("This is row 2 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.writeln("This is row 2 cell 2");
        
        builder.endRow();
        
        builder.endTable();

        Example:

        Shows how to create a table that contains a single formatted cell.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        builder.insertCell();
        
        // Set the cell formatting
        CellFormat cellFormat = builder.getCellFormat();
        cellFormat.setWidth(250);
        cellFormat.setLeftPadding(30);
        cellFormat.setRightPadding(30);
        cellFormat.setTopPadding(30);
        cellFormat.setBottomPadding(30);
        
        builder.writeln("I'm a wonderful formatted cell.");
        
        builder.endRow();
        builder.endTable();
      • insertBreak

        public void insertBreak(int breakType)
        Inserts a break of the specified type into the document. Use this method to insert paragraph, page, column, section or line break into the document.
        Parameters:
        breakType - A BreakType value. Specifies the type of the break to insert.

        Example:

        Demonstrates how to insert a Table of contents (TOC) into a document using heading styles as entries.
        // Use a blank document
        Document doc = new Document();
        // Create a document builder to insert content with into document.
        DocumentBuilder builder = new DocumentBuilder(doc);
        // Insert a table of contents at the beginning of the document.
        builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
        // Start the actual document content on the second page.
        builder.insertBreak(BreakType.PAGE_BREAK);
        // Build a document with complex structure by applying different heading styles thus creating TOC entries.
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        
        builder.writeln("Heading 1");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 1.1");
        builder.writeln("Heading 1.2");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        
        builder.writeln("Heading 2");
        builder.writeln("Heading 3");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 3.1");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_3);
        
        builder.writeln("Heading 3.1.1");
        builder.writeln("Heading 3.1.2");
        builder.writeln("Heading 3.1.3");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 3.2");
        builder.writeln("Heading 3.3");
        
        // Call the method below to update the TOC.
        doc.updateFields();

        Example:

        Creates headers and footers in a document using DocumentBuilder.
        // Create a blank document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want headers and footers different for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header First");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header Even");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header Odd");
        
        // Create three pages in the document.
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.HeadersAndFooters.doc");

        Example:

        Shows how to insert sections using DocumentBuilder, specify page setup for a section and reset page setup to defaults.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Modify the first section in the document.
        builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
        builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
        builder.writeln("Section 1, landscape oriented and text vertically centered.");
        
        // Start a new section and reset its formatting to defaults.
        builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
        builder.getPageSetup().clearFormatting();
        builder.writeln("Section 2, back to default Letter paper size, portrait orientation and top alignment.");
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\PageSetup.ClearFormatting.doc");
      • insertCell

        public Cell insertCell()
        Inserts a table cell into the document.

        To start a table, just call InsertCell. After this, any content you add using other methods of the DocumentBuilder class will be added to the current cell.

        To start a new cell in the same row, call InsertCell again.

        To end a table row call endRow().

        Use the CellFormat property to specify cell formatting.

        Returns:
        The cell node that was just inserted.

        Example:

        Shows how to create a formatted table using DocumentBuilder
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Make the header row.
        builder.insertCell();
        
        // Set the left indent for the table. Table wide formatting must be applied after
        // at least one row is present in the table.
        table.setLeftIndent(20.0);
        
        // Set height and define the height rule for the header row.
        builder.getRowFormat().setHeight(40.0);
        builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);
        
        // Some special features for the header row.
        builder.getCellFormat().getShading().setBackgroundPatternColor(new Color(198, 217, 241));
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        builder.getFont().setSize(16);
        builder.getFont().setName("Arial");
        builder.getFont().setBold(true);
        
        builder.getCellFormat().setWidth(100.0);
        builder.write("Header Row,\n Cell 1");
        
        // We don't need to specify the width of this cell because it's inherited from the previous cell.
        builder.insertCell();
        builder.write("Header Row,\n Cell 2");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Header Row,\n Cell 3");
        builder.endRow();
        
        // Set features for the other rows and cells.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
        builder.getCellFormat().setWidth(100.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        
        // Reset height and define a different height rule for table body
        builder.getRowFormat().setHeight(30.0);
        builder.getRowFormat().setHeightRule(HeightRule.AUTO);
        builder.insertCell();
        // Reset font formatting.
        builder.getFont().setSize(12);
        builder.getFont().setBold(false);
        
        // Build the other cells.
        builder.write("Row 1, Cell 1 Content");
        builder.insertCell();
        builder.write("Row 1, Cell 2 Content");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Row 1, Cell 3 Content");
        builder.endRow();
        
        builder.insertCell();
        builder.getCellFormat().setWidth(100.0);
        builder.write("Row 2, Cell 1 Content");
        
        builder.insertCell();
        builder.write("Row 2, Cell 2 Content");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Row 2, Cell 3 Content.");
        builder.endRow();
        builder.endTable();
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateFormattedTable.doc");

        Example:

        Shows how to build a formatted table that contains 2 rows and 2 columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Insert a cell
        builder.insertCell();
        // Use fixed column widths.
        table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
        
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("This is row 1 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.write("This is row 1 cell 2");
        
        builder.endRow();
        
        // Insert a cell
        builder.insertCell();
        
        // Apply new row formatting
        builder.getRowFormat().setHeight(100);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.writeln("This is row 2 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.writeln("This is row 2 cell 2");
        
        builder.endRow();
        
        builder.endTable();

        Example:

        Shows how to create a simple table using DocumentBuilder with default formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // We call this method to start building the table.
        builder.startTable();
        builder.insertCell();
        builder.write("Row 1, Cell 1 Content.");
        
        // Build the second cell
        builder.insertCell();
        builder.write("Row 1, Cell 2 Content.");
        // Call the following method to end the row and start a new row.
        builder.endRow();
        
        // Build the first cell of the second row.
        builder.insertCell();
        builder.write("Row 2, Cell 1 Content");
        
        // Build the second cell.
        builder.insertCell();
        builder.write("Row 2, Cell 2 Content.");
        builder.endRow();
        
        // Signal that we have finished building the table.
        builder.endTable();
        
        // Save the document to disk.
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateSimpleTable.doc");

        Example:

        Creates a table with two columns with cells merged vertically in the first column.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
        builder.write("Text in merged cells.");
        
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
        builder.write("Text in one cell");
        builder.endRow();
        
        builder.insertCell();
        // This cell is vertically merged to the cell above and should be empty.
        builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
        
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
        builder.write("Text in another cell");
        builder.endRow();
        builder.endTable();
      • insertChart

        public Shape insertChart(int chartType, double width, double height)
                         throws java.lang.Exception
        Inserts an chart object into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        chartType - A ChartType value. The chart type to insert into the document.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to insert a chart into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertChart(ChartType.PIE, ConvertUtil.pixelToPoint(300.0), ConvertUtil.pixelToPoint(300.0));
        
        doc.save(getMyDir() + "\\Artifacts\\Document.InsertedChartDouble.doc");
      • insertChart

        public Shape insertChart(int chartType, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                         throws java.lang.Exception
        Inserts an chart object into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        chartType - A ChartType value. The chart type to insert into the document.
        horzPos - A RelativeHorizontalPosition value. Specifies where the distance to the image is measured from.
        left - Distance in points from the origin to the left side of the image.
        vertPos - A RelativeVerticalPosition value. Specifies where the distance to the image measured from.
        top - Distance in points from the origin to the top side of the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        wrapType - A WrapType value. Specifies how to wrap text around the image.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to insert a chart into a document and specify position and size.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertChart(ChartType.PIE, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN, 100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getMyDir() + "\\Artifacts\\Document.InsertedChartRelativePosition.doc");
      • insertCheckBox

        public FormField insertCheckBox(java.lang.String name, boolean defaultValue, boolean checkedValue, int size)
                                throws java.lang.Exception
        Inserts a checkbox form field at the current position.

        If you specify a name for the form field, then a bookmark is automatically created with the same name.

        Parameters:
        name - The name of the form field. Can be an empty string. The value longer than 20 characters will be truncated.
        defaultValue - Default value of the checkbox form field.
        checkedValue - Current checked status of the checkbox form field.
        size - Specifies the size of the checkbox in points. Specify 0 for MS Word to calculate the size of the checkbox automatically.
        Returns:
        The form field node that was just inserted.

        Example:

        Shows how to insert checkboxes to the document
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertCheckBox("", false, false, 0);
        builder.insertCheckBox("CheckBox_Default", true, true, 50);
        builder.insertCheckBox("CheckBox_OnlyCheckedValue", true, 100);
      • insertCheckBox

        public FormField insertCheckBox(java.lang.String name, boolean checkedValue, int size)
                                throws java.lang.Exception
        Inserts a checkbox form field at the current position.

        If you specify a name for the form field, then a bookmark is automatically created with the same name.

        Parameters:
        name - The name of the form field. Can be an empty string. The value longer than 20 characters will be truncated.
        checkedValue - Checked status of the checkbox form field.
        size - Specifies the size of the checkbox in points. Specify 0 for MS Word to calculate the size of the checkbox automatically.
        Returns:
        The form field node that was just inserted.

        Example:

        Shows how to insert checkbox form fields into a document during mail merge.
        // File 'MailMerge.InsertCheckBox.doc' is a template
        // containing the table with the following fields in it:
        // <<TableStart:StudentCourse>> <<CourseName>> <<TableEnd:StudentCourse>>.
        
        public void mailMergeInsertCheckBox() throws Exception
        {
            Document doc = new Document(getMyDir() + "MailMerge.InsertCheckBox.doc");
        
            // Add a handler for the MergeField event.
            doc.getMailMerge().setFieldMergingCallback(new HandleMergeFieldInsertCheckBox());
        
            // Execute mail merge with regions.
            DataTable dataTable = getStudentCourseDataTable();
            doc.getMailMerge().executeWithRegions(dataTable);
        
            // Save resulting document with a new name.
            doc.save(getMyDir() + "\\Artifacts\\MailMerge.InsertCheckBox.doc");
        }
        
        private class HandleMergeFieldInsertCheckBox implements IFieldMergingCallback
        {
            /**
             * This is called for each merge field in the document
             * when Document.MailMerge.ExecuteWithRegions is called.
             */
            public void fieldMerging(FieldMergingArgs e) throws Exception
            {
                if (e.getDocumentFieldName().equals("CourseName"))
                {
                    // Insert the checkbox for this merge field, using DocumentBuilder.
                    DocumentBuilder builder = new DocumentBuilder(e.getDocument());
                    builder.moveToMergeField(e.getFieldName());
                    builder.insertCheckBox(e.getDocumentFieldName() + Integer.toString(mCheckBoxCount), false, 0);
                    builder.write((String) e.getFieldValue());
                    mCheckBoxCount++;
                }
            }
        
            public void imageFieldMerging(ImageFieldMergingArgs args)
            {
                // Do nothing.
            }
        
            /**
             * Counter for CheckBox name generation
             */
            private int mCheckBoxCount;
        }
        
        /**
         * Create DataTable and fill it with data.
         * In real life this DataTable should be filled from a database.
         */
        private static DataTable getStudentCourseDataTable() throws Exception
        {
            DataTable dataTable = new DataTable("StudentCourse");
            dataTable.getColumns().add("CourseName");
            for (int i = 0; i < 10; i++)
            {
                DataRow datarow = dataTable.newRow();
                dataTable.getRows().add(datarow);
                datarow.set(0, "Course " + Integer.toString(i));
            }
            return dataTable;
        }

        Example:

        Shows how to insert checkboxes to the document
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertCheckBox("", false, false, 0);
        builder.insertCheckBox("CheckBox_Default", true, true, 50);
        builder.insertCheckBox("CheckBox_OnlyCheckedValue", true, 100);
      • insertComboBox

        public FormField insertComboBox(java.lang.String name, java.lang.String[] items, int selectedIndex)
                                throws java.lang.Exception
        Inserts a combobox form field at the current position.

        If you specify a name for the form field, then a bookmark is automatically created with the same name.

        Parameters:
        name - The name of the form field. Can be an empty string. The value longer than 20 characters will be truncated.
        items - The items of the ComboBox. Maximum is 25 items.
        selectedIndex - The index of the selected item in the ComboBox.
        Returns:
        The form field node that was just inserted.

        Example:

        Builds a sample form to fill.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Insert a text form field for input a name.
        builder.insertTextInput("", TextFormFieldType.REGULAR, "", "Enter your name here", 30);
        
        // Insert two blank lines.
        builder.writeln("");
        builder.writeln("");
        
        String[] items = new String[]{"-- Select your favorite footwear --", "Sneakers", "Oxfords", "Flip-flops", "Other", "I prefer to be barefoot"};
        
        // Insert a combo box to select a footwear type.
        builder.insertComboBox("", items, 0);
        
        // Insert two blank lines.
        builder.writeln("");
        builder.writeln("");
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateForm.doc");

        Example:

        Shows how to insert a combobox form field into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        String[] items = {"One", "Two", "Three"};
        builder.insertComboBox("DropDown", items, 0);
      • insertDocument

        public Node insertDocument(Document srcDoc, int importFormatMode)
        Inserts content of the document into the current position of DocumentBuilder's cursor. This method mimics the MS Word behavior, as if CTRL+'A' (select all content) was pressed, then CTRL+'C' (copy selected into the buffer) inside one document and then CTRL+'V' (insert content from the buffer) inside another document.
        Parameters:
        srcDoc - Source document for inserting.
        importFormatMode - A ImportFormatMode value. Specifies how to merge style formatting that clashes.
        Returns:
        First inserted node.

        Example:

        Shows how to insert a document content into another document.
        Document doc = new Document(getMyDir() + "Document.docx");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Document docToInsert = new Document(getMyDir() + "DocumentBuilder.InsertedDoc.docx");
        
        builder.insertDocument(docToInsert, ImportFormatMode.KEEP_SOURCE_FORMATTING);
      • insertField

        public Field insertField(int fieldType, boolean updateField)
                         throws java.lang.Exception
        Inserts a Word field into a document and optionally updates the field result.

        This method inserts a field into a document. Aspose.Words can update fields of most types, but not all. For more details see the insertField(java.lang.String,java.lang.String) overload.

        Parameters:
        fieldType - A FieldType value. The type of the field to append.
        updateField - Specifies whether to update the field immediately.
        Returns:
        A Field object that represents the inserted field.
        See Also:
        Field

        Example:

        Shows how to insert a field into a document using FieldType
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.write("This field was inserted/updated at ");
        builder.insertField(FieldType.FIELD_TIME, true);
        
        doc.save(getMyDir() + "\\Artifacts\\Document.InsertedField.doc");
      • insertField

        public Field insertField(java.lang.String fieldCode)
                         throws java.lang.Exception
        Inserts a Word field into a document and updates the field result.

        This method inserts a field into a document and updates the field result immediately. Aspose.Words can update fields of most types, but not all. For more details see the insertField(java.lang.String,java.lang.String) overload.

        Parameters:
        fieldCode - The field code to insert (without curly braces).
        Returns:
        A Field object that represents the inserted field.
        See Also:
        Field

        Example:

        Inserts a field into a document using DocumentBuilder and FieldCode.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a simple Date field into the document.
        // When we insert a field through the DocumentBuilder class we can get the
        // special Field object which contains information about the field.
        Field dateField = builder.insertField("DATE \\* MERGEFORMAT");
        
        // Update this particular field in the document so we can get the FieldResult.
        dateField.update();
        
        // Display some information from this field.
        // The field result is where the last evaluated value is stored. This is what is displayed in the document
        // When field codes are not showing.
        System.out.println(MessageFormat.format("FieldResult: {0}", dateField.getResult()));
        
        // Display the field code which defines the behaviour of the field. This can been seen in Microsoft Word by pressing ALT+F9.
        System.out.println(MessageFormat.format("FieldCode: {0}", dateField.getFieldCode()));
        
        // The field type defines what type of field in the Document this is. In this case the type is "FieldDate"
        System.out.println(MessageFormat.format("FieldType: {0}", dateField.getType()));
        
        // Finally let's completely remove the field from the document. This can easily be done by invoking the Remove method on the object.
        dateField.remove();

        Example:

        Inserts a merge field into a document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.insertField("MERGEFIELD MyFieldName \\* MERGEFORMAT");
      • insertField

        public Field insertField(java.lang.String fieldCode, java.lang.String fieldValue)
        Inserts a Word field into a document without updating the field result.

        Fields in Microsoft Word documents consist of a field code and a field result. The field code is like a formula and the field result is like the value that the formula produces. The field code may also contain field switches that are like additional instructions to perform a specific action.

        You can switch between displaying field codes and results in your document in Microsoft Word using the keyboard shortcut Alt+F9. Field codes appear between curly braces ( { } ).

        To create a field, you need to specify a field type, field code and a "placeholder" field value. If you are not sure about a particular field code syntax, create the field in Microsoft Word first and switch to see its field code.

        Aspose.Words can calculate field results for most of the field types, but this method does not update the field result automatically. Because the field result is not calculated automatically, you are expected to pass some string value (or even an empty string) that will be inserted into the field result. This value will remain in the field result as a placeholder until the field is updated. To update the field result you can call Field.update() on the field object returned to you or Document.updateFields() to update fields in the whole document.

        Parameters:
        fieldCode - The field code to insert (without curly braces).
        fieldValue - The field value to insert. Pass null for fields that do not have a value.
        Returns:
        A Field object that represents the inserted field.
        See Also:
        Field

        Example:

        Shows how to control page numbering per section.
        // This document has two sections, but no page numbers yet.
        Document doc = new Document(getMyDir() + "PageSetup.PageNumbering.doc");
        
        // Use document builder to create a header with a page number field for the first section.
        // The page number will look like "Page V".
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.moveToSection(0);
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Page ");
        builder.insertField("PAGE", "");
        
        // Set first section page numbering.
        Section section = doc.getSections().get(0);
        section.getPageSetup().setRestartPageNumbering(true);
        section.getPageSetup().setPageStartingNumber(5);
        section.getPageSetup().setPageNumberStyle(NumberStyle.UPPERCASE_ROMAN);
        
        // Create a header for the section. 
        // The page number will look like " - 10 - ".
        builder.moveToSection(1);
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        builder.write(" - ");
        builder.insertField("PAGE", "");
        builder.write(" - ");
        
        // Set second section page numbering.
        section = doc.getSections().get(1);
        section.getPageSetup().setPageStartingNumber(10);
        section.getPageSetup().setRestartPageNumbering(true);
        section.getPageSetup().setPageNumberStyle(NumberStyle.ARABIC);
        
        doc.save(getMyDir() + "\\Artifacts\\PageSetup.PageNumbering.doc");
      • insertFootnote

        public Footnote insertFootnote(int footnoteType, java.lang.String footnoteText)
        Inserts a footnote or endnote into the document.
        Parameters:
        footnoteType - A FootnoteType value. Specifies whether to insert a footnote or an endnote.
        footnoteText - Specifies the text of the footnote.
        Returns:
        Returns a footnote object that was just created.

        Example:

        Shows how to add a footnote to a paragraph in the document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        for (int i = 0; i <= 100; i++)
        {
            builder.write("Some text " + i);
        
            builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text " + i);
            builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text " + i, "242");
        }
      • insertFootnote

        public Footnote insertFootnote(int footnoteType, java.lang.String footnoteText, java.lang.String referenceMark)
        Inserts a footnote or endnote into the document.
        Parameters:
        footnoteType - A FootnoteType value. Specifies whether to insert a footnote or an endnote.
        footnoteText - Specifies the text of the footnote.
        referenceMark - Specifies the custom reference mark of the footnote.
        Returns:
        Returns a footnote object that was just created.

        Example:

        Shows how to add a footnote to a paragraph in the document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        for (int i = 0; i <= 100; i++)
        {
            builder.write("Some text " + i);
        
            builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text " + i);
            builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text " + i, "242");
        }
      • insertHorizontalRule

        public void insertHorizontalRule()
                                 throws java.lang.Exception
        Inserts a horizontal rule shape into the document.
      • insertHtml

        public void insertHtml(java.lang.String html)
                       throws java.lang.Exception
        Inserts an HTML string into the document.

        You can use InsertHtml to insert an HTML fragment or whole HTML document.

        Parameters:
        html - An HTML string to insert into the document.

        Example:

        Shows how to mail merge HTML data into a document.
        // File 'MailMerge.InsertHtml.doc' has merge field named 'htmlField1' in it.
        // File 'MailMerge.HtmlData.html' contains some valid HTML data.
        // The same approach can be used when merging HTML data from database.
        
        public void mailMergeInsertHtml() throws Exception
        {
            Document doc = new Document(getMyDir() + "MailMerge.InsertHtml.doc");
        
            // Add a handler for the MergeField event.
            doc.getMailMerge().setFieldMergingCallback(new HandleMergeFieldInsertHtml());
        
            // Load some Html from file.
            StringBuilder htmlText = new StringBuilder();
            BufferedReader reader = new BufferedReader(new FileReader(getMyDir() + "MailMerge.HtmlData.html"));
            String line;
            while ((line = reader.readLine()) != null)
            {
                htmlText.append(line);
                htmlText.append("\r\n");
            }
        
            // Execute mail merge.
            doc.getMailMerge().execute(new String[]{"htmlField1"}, new String[]{htmlText.toString()});
        
            // Save resulting document with a new name.
            doc.save(getMyDir() + "\\Artifacts\\MailMerge.InsertHtml.doc");
        }
        
        private class HandleMergeFieldInsertHtml implements IFieldMergingCallback
        {
            /**
             * This is called when merge field is actually merged with data in the document.
             */
            public void fieldMerging(FieldMergingArgs e) throws Exception
            {
                // All merge fields that expect HTML data should be marked with some prefix, e.g. 'html'.
                if (e.getDocumentFieldName().startsWith("html"))
                {
                    // Insert the text for this merge field as HTML data, using DocumentBuilder.
                    DocumentBuilder builder = new DocumentBuilder(e.getDocument());
                    builder.moveToMergeField(e.getDocumentFieldName());
                    builder.insertHtml((String) e.getFieldValue());
        
                    // The HTML text itself should not be inserted.
                    // We have already inserted it as an HTML.
                    e.setText("");
                }
            }
        
            public void imageFieldMerging(ImageFieldMergingArgs e)
            {
                // Do nothing.
            }
        }

        Example:

        Replaces text specified with regular expression with HTML.
        public void replaceWithInsertHtml() throws Exception
        {
            // Open the document.
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            builder.writeln("Hello <CustomerName>,");
        
            FindReplaceOptions options = new FindReplaceOptions();
            options.setReplacingCallback(new ReplaceWithHtmlEvaluator(options));
        
            doc.getRange().replace(Pattern.compile(" <CustomerName>,"), "", options);
        
            // Save the modified document.
            doc.save(getMyDir() + "\\Artifacts\\Range.ReplaceWithInsertHtml.doc");
        
        }
        
        private class ReplaceWithHtmlEvaluator implements IReplacingCallback
        {
            ReplaceWithHtmlEvaluator(FindReplaceOptions options)
            {
                mOptions = options;
            }
        
            /**
             * NOTE: This is a simplistic method that will only work well when the match
             * starts at the beginning of a run.
             */
            public int replacing(ReplacingArgs e) throws Exception
            {
                DocumentBuilder builder = new DocumentBuilder((Document) e.getMatchNode().getDocument());
                builder.moveTo(e.getMatchNode());
        
                // Replace '<CustomerName>' text with a red bold name.
                builder.insertHtml("<b><font color='red'>James Bond, </font></b>");
                e.setReplacement("");
        
                return ReplaceAction.REPLACE;
            }
        
            private /*final*/ FindReplaceOptions mOptions;
        }

        Example:

        Inserts HTML into a document. The formatting specified in the HTML is applied.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertHtml("<P align='right'>Paragraph right</P>" + "<b>Implicit paragraph left</b>" + "<div align='center'>Div center</div>" + "<h1 align='left'>Heading 1 left.</h1>");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertHtml.doc");

        Example:

        Inserts MathMl into a document using.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        final String MATH_ML =
            "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><msub><mi>a</mi><mrow><mn>1</mn></mrow></msub><mo>+</mo><msub><mi>b</mi><mrow><mn>1</mn></mrow></msub></mrow></math>";
        
        builder.insertHtml(MATH_ML);
      • insertHtml

        public void insertHtml(java.lang.String html, boolean useBuilderFormatting)
                       throws java.lang.Exception
        Inserts an HTML string into the document.

        You can use InsertHtml to insert an HTML fragment or whole HTML document.

        When useBuilderFormatting is false, DocumentBuilder formating is ignored and formatting of inserted text is based on default HTML formatting. As a result, the text looks as it is rendered in browsers.

        When useBuilderFormatting is true, formatting of inserted text is based on DocumentBuilder formatting, and the text looks as if it were inserted with write(java.lang.String).

        Parameters:
        html - An HTML string to insert into the document.
        useBuilderFormatting - A value indicating whether formatting specified in DocumentBuilder is used as base formatting for text imported from HTML.

        Example:

        Inserts HTML into a document using. The current document formatting at the insertion position is applied to the inserted text.
        Document doc = new Document();
        
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.insertHtml(
            "<P align='right'>Paragraph right</P>" + "<b>Implicit paragraph left</b>" +
            "<div align='center'>Div center</div>" + "<h1 align='left'>Heading 1 left.</h1>", true);
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertHtml.doc");
      • insertHyperlink

        public Field insertHyperlink(java.lang.String displayText, java.lang.String urlOrBookmark, boolean isBookmark)
        Inserts a hyperlink into the document.

        Note that you need to specify font formatting for the hyperlink display text explicitly using the Font property.

        This methods internally calls insertField(java.lang.String) to insert an MS Word HYPERLINK field into the document.

        Parameters:
        displayText - Text of the link to be displayed in the document.
        urlOrBookmark - Link destination. Can be a url or a name of a bookmark inside the document. This method always adds apostrophes at the beginning and end of the url.
        isBookmark - True if the previous parameter is a name of a bookmark inside the document; false is the previous parameter is a URL.
        Returns:
        A Field object that represents the inserted field.

        Example:

        Shows how to use temporarily save and restore character formatting when building a document with DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set up font formatting and write text that goes before the hyperlink.
        builder.getFont().setName("Arial");
        builder.getFont().setSize(24);
        builder.getFont().setBold(true);
        builder.write("To go to an important location, click ");
        
        // Save the font formatting so we use different formatting for hyperlink and restore old formatting later.
        builder.pushFont();
        
        // Set new font formatting for the hyperlink and insert the hyperlink.
        // The "Hyperlink" style is a Microsoft Word built-in style so we don't have to worry to
        // create it, it will be created automatically if it does not yet exist in the document.
        builder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
        builder.insertHyperlink("here", "http://www.google.com", false);
        
        // Restore the formatting that was before the hyperlink.
        builder.popFont();
        
        builder.writeln(". We hope you enjoyed the example.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.PushPopFont.doc");

        Example:

        Inserts a hyperlink referencing local bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startBookmark("Bookmark1");
        builder.write("Bookmarked text.");
        builder.endBookmark("Bookmark1");
        
        builder.writeln("Some other text");
        
        // Specify font formatting for the hyperlink.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        
        // Insert hyperlink.
        // Switch \o is used to provide hyperlink tip text.
        builder.insertHyperlink("Hyperlink Text", "Bookmark1\" \\o \"Hyperlink Tip", true);
        
        // Clear hyperlink formatting.
        builder.getFont().clearFormatting();
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertHyperlinkToLocalBookmark.doc");

        Example:

        Inserts a hyperlink into a document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.write("Please make sure to visit ");
        
        // Specify font formatting for the hyperlink.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        // Insert the link.
        builder.insertHyperlink("Aspose Website", "http://www.aspose.com", false);
        
        // Revert to default formatting.
        builder.getFont().clearFormatting();
        
        builder.write(" for more information.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertHyperlink.doc");
      • insertImage

        public Shape insertImage(byte[] imageBytes)
                         throws java.lang.Exception
        Inserts an image from a byte array into the document. The image is inserted inline and at 100% scale.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        imageBytes - The byte array that contains the image.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to import an image into a document from a byte array.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Prepare a byte array of an image.
        byte[] imageBytes = DocumentHelper.convertImageToByteArray(new File(getImageDir() + "Aspose.Words.gif"), "gif");
        
        builder.insertImage(imageBytes);
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromByteArrayDefault.doc");
      • insertImage

        public Shape insertImage(byte[] imageBytes, double width, double height)
                         throws java.lang.Exception
        Inserts an inline image from a byte array into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        imageBytes - The byte array that contains the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to import an image into a document from a byte array, with a custom size.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Prepare a byte array of an image.
        byte[] imageBytes = DocumentHelper.convertImageToByteArray(new File(getImageDir() + "Aspose.Words.gif"), "gif");
        
        builder.insertImage(imageBytes, ConvertUtil.pixelToPoint(450.0), ConvertUtil.pixelToPoint(144.0));
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromByteArrayCustomSize.doc");
      • insertImage

        public Shape insertImage(byte[] imageBytes, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                         throws java.lang.Exception
        Inserts an image from a byte array at the specified position and size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        imageBytes - The byte array that contains the image.
        horzPos - A RelativeHorizontalPosition value. Specifies where the distance to the image is measured from.
        left - Distance in points from the origin to the left side of the image.
        vertPos - A RelativeVerticalPosition value. Specifies where the distance to the image measured from.
        top - Distance in points from the origin to the top side of the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        wrapType - A WrapType value. Specifies how to wrap text around the image.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to import an image into a document from a byte array, also using relative positions.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Prepare a byte array of an image.
        byte[] imageBytes = DocumentHelper.convertImageToByteArray(new File(getImageDir() + "Aspose.Words.gif"), "gif");
        
        builder.insertImage(imageBytes, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN, 100.0, 200.0, 100.0, WrapType.SQUARE);
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromByteArrayRelativePosition.doc");
      • insertImage

        public Shape insertImage(java.awt.image.BufferedImage image)
                         throws java.lang.Exception
        Inserts an image from a java.awt.image.BufferedImage object into the document. The image is inserted inline and at 100% scale.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Aspose.Words will insert the image in the PNG format and with default settings. If you want to insert a BufferedImage in another format or with other settings, you need to save the image into a byte array and use insertImage(byte[]).

        Parameters:
        image - The image to insert into the document.
        Returns:
        The image node that was just inserted.

        Example:

        Inserts a watermark image into a document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // The best place for the watermark image is in the header or footer so it is shown on every page.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        
        BufferedImage image = ImageIO.read(new File(getImageDir() + "Watermark.png"));
        
        // Insert a floating picture.
        Shape shape = builder.insertImage(image);
        shape.setWrapType(WrapType.NONE);
        shape.setBehindText(true);
        
        shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        
        // Calculate image left and top position so it appears in the centre of the page.
        shape.setLeft((builder.getPageSetup().getPageWidth() - shape.getWidth()) / 2);
        shape.setTop((builder.getPageSetup().getPageHeight() - shape.getHeight()) / 2);
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertWatermark.doc");

        Example:

        Shows how to insert a .NET Image object into a document. The image is inserted inline and at 100% scale.
        // This creates a builder and also an empty document inside the builder.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Insert a raster image.
        BufferedImage rasterImage = ImageIO.read(new File(getMyDir() + "\\Images\\Aspose.Words.gif"));
        builder.write("Raster image: ");
        builder.insertImage(rasterImage);
        builder.writeln();
        
        // Aspose.Words allows to insert a metafile too, but on Java you should specify a filename or a stream, not a BufferedImage.
        builder.write("Metafile: ");
        builder.insertImage(getMyDir() + "\\Images\\Hammer.wmf");
        builder.writeln();
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromImage.doc");
      • insertImage

        public Shape insertImage(java.awt.image.BufferedImage image, double width, double height)
                         throws java.lang.Exception
        Inserts an inline image from a java.awt.image.BufferedImage object into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Aspose.Words will insert the image in the PNG format and with default settings. If you want to insert a BufferedImage in another format or with other settings, you need to save the image into a byte array and use insertImage(byte[]).

        Parameters:
        image - The image to insert into the document.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to import an image into a document, with a custom size.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        BufferedImage rasterImage = ImageIO.read(new File(getImageDir() + "Aspose.Words.gif"));
        try
        {
            builder.insertImage(rasterImage, ConvertUtil.pixelToPoint(450.0), ConvertUtil.pixelToPoint(144.0));
            builder.writeln();
        } finally
        {
            rasterImage.flush();
        }
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromImageWithStreamCustomSize.doc");
      • insertImage

        public Shape insertImage(java.awt.image.BufferedImage image, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                         throws java.lang.Exception
        Inserts an image from a java.awt.image.BufferedImage object at the specified position and size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Aspose.Words will insert the image in the PNG format and with default settings. If you want to insert a BufferedImage in another format or with other settings, you need to save the image into a byte array and use insertImage(byte[]).

        Parameters:
        image - The image to insert into the document.
        horzPos - A RelativeHorizontalPosition value. Specifies where the distance to the image is measured from.
        left - Distance in points from the origin to the left side of the image.
        vertPos - A RelativeVerticalPosition value. Specifies where the distance to the image measured from.
        top - Distance in points from the origin to the top side of the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        wrapType - A WrapType value. Specifies how to wrap text around the image.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to import an image into a document, also using relative positions.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        BufferedImage rasterImage = ImageIO.read(new File(getImageDir() + "Aspose.Words.gif"));
        try
        {
            builder.insertImage(rasterImage, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN, 100.0, 200.0, 100.0, WrapType.SQUARE);
        } finally
        {
            rasterImage.flush();
        }
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromImageWithStreamRelativePosition.doc");
      • insertImage

        public Shape insertImage(java.io.InputStream stream)
                         throws java.lang.Exception
        Inserts an image from a stream into the document. The image is inserted inline and at 100% scale.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        stream - The stream that contains the image. The stream will be read from the current position, so one should be careful about stream position.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to insert an image from a stream. The image is inserted inline and at 100% scale.
        // This creates a builder and also an empty document inside the builder.
        DocumentBuilder builder = new DocumentBuilder();
        
        InputStream stream = new FileInputStream(getMyDir() + "\\Images\\Aspose.Words.gif");
        try
        {
            builder.write("Image from stream: ");
            builder.insertImage(stream);
        } finally
        {
            stream.close();
        }
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromStream.doc");
      • insertImage

        public Shape insertImage(java.io.InputStream stream, double width, double height)
                         throws java.lang.Exception
        Inserts an inline image from a stream into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        stream - The stream that contains the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to import an image from a stream into a document with a custom size.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        FileInputStream stream = new FileInputStream(getImageDir() + "Aspose.Words.gif");
        try
        {
            builder.insertImage(stream, ConvertUtil.pixelToPoint(400.0), ConvertUtil.pixelToPoint(400.0));
        } finally
        {
            stream.close();
        }
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromStreamCustomSize.doc");
      • insertImage

        public Shape insertImage(java.io.InputStream stream, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                         throws java.lang.Exception
        Inserts an image from a stream at the specified position and size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        stream - The stream that contains the image.
        horzPos - A RelativeHorizontalPosition value. Specifies where the distance to the image is measured from.
        left - Distance in points from the origin to the left side of the image.
        vertPos - A RelativeVerticalPosition value. Specifies where the distance to the image measured from.
        top - Distance in points from the origin to the top side of the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        wrapType - A WrapType value. Specifies how to wrap text around the image.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to insert an image into a document from a stream, also using relative positions.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        FileInputStream stream = new FileInputStream(getImageDir() + "Aspose.Words.gif");
        try
        {
            builder.insertImage(stream, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN, 100.0, 200.0, 100.0, WrapType.SQUARE);
        } finally
        {
            stream.close();
        }
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromStreamRelativePosition.doc");
      • insertImage

        public Shape insertImage(java.lang.String fileName)
                         throws java.lang.Exception
        Inserts an image from a file or URL into the document. The image is inserted inline and at 100% scale.

        This overload will automatically download the image before inserting into the document if you specify a remote URI.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        fileName - The file with the image. Can be any valid local or remote URI.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to insert a floating image in the middle of a page.
        // This creates a builder and also an empty document inside the builder.
        DocumentBuilder builder = new DocumentBuilder();
        
        // By default, the image is inline.
        Shape shape = builder.insertImage(getMyDir() + "\\Images\\Aspose.Words.gif");
        
        // Make the image float, put it behind text and center on the page.
        shape.setWrapType(WrapType.NONE);
        shape.setBehindText(true);
        shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
        shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        shape.setVerticalAlignment(VerticalAlignment.CENTER);
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFloatingPageCenter.doc");

        Example:

        Shows how to inserts an image from a URL. The image is inserted inline and at 100% scale.
        // This creates a builder and also an empty document inside the builder.
        DocumentBuilder builder = new DocumentBuilder();
        
        builder.write("Image from local file: ");
        builder.insertImage(getMyDir() + "\\Images\\Aspose.Words.gif");
        builder.writeln();
        
        builder.write("Image from an Internet url, automatically downloaded for you: ");
        builder.insertImage("http://www.aspose.com/Images/aspose-logo.jpg");
        builder.writeln();
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateFromUrl.doc");

        Example:

        Shows how to insert an image into a document from a web address.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.insertImage("http://www.aspose.com/images/aspose-logo.gif");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertImageFromUrl.doc");
      • insertImage

        public Shape insertImage(java.lang.String fileName, double width, double height)
                         throws java.lang.Exception
        Inserts an inline image from a file or URL into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        fileName - The file that contains the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to import an image from a url into a document with a custom size.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertImage(getImageDir() + "Aspose.Words.gif", ConvertUtil.pixelToPoint(400.0), ConvertUtil.pixelToPoint(400.0));
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertImageFromUrlCustomSize.doc");
      • insertImage

        public Shape insertImage(java.lang.String fileName, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                         throws java.lang.Exception
        Inserts an image from a file or URL at the specified position and size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        fileName - The file that contains the image.
        horzPos - A RelativeHorizontalPosition value. Specifies where the distance to the image is measured from.
        left - Distance in points from the origin to the left side of the image.
        vertPos - A RelativeVerticalPosition value. Specifies where the distance to the image measured from.
        top - Distance in points from the origin to the top side of the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        wrapType - A WrapType value. Specifies how to wrap text around the image.
        Returns:
        The image node that was just inserted.

        Example:

        Shows how to insert a floating image from a file or URL and retain the original image size in the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Pass a negative value to the width and height values to specify using the size of the source image.
        builder.insertImage(getImageDir() + "LogoSmall.png", RelativeHorizontalPosition.MARGIN, 200.0, RelativeVerticalPosition.MARGIN, 100.0, -1, -1, WrapType.SQUARE);

        Example:

        Shows how to insert a floating image from a file or URL.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertImage(getImageDir() + "Watermark.png", RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN, 100.0, 200.0, 100.0, WrapType.SQUARE);
      • insertNode

        public void insertNode(Node node)
        Inserts a text level node inside the current paragraph before the cursor.

        Example:

        Shows how to insert a linked image into a document.
        DocumentBuilder builder = new DocumentBuilder();
        
        String imageFileName = getMyDir() + "\\Images\\Hammer.wmf";
        
        builder.write("Image linked, not stored in the document: ");
        
        Shape linkedOnly = new Shape(builder.getDocument(), ShapeType.IMAGE);
        linkedOnly.setWrapType(WrapType.INLINE);
        linkedOnly.getImageData().setSourceFullName(imageFileName);
        
        builder.insertNode(linkedOnly);
        builder.writeln();
        
        builder.write("Image linked and stored in the document: ");
        
        Shape linkedAndStored = new Shape(builder.getDocument(), ShapeType.IMAGE);
        linkedAndStored.setWrapType(WrapType.INLINE);
        linkedAndStored.getImageData().setSourceFullName(imageFileName);
        linkedAndStored.getImageData().setImage(imageFileName);
        
        builder.insertNode(linkedAndStored);
        builder.writeln();
        
        builder.write("Image stored in the document, but not linked: ");
        
        Shape stored = new Shape(builder.getDocument(), ShapeType.IMAGE);
        stored.setWrapType(WrapType.INLINE);
        stored.getImageData().setImage(imageFileName);
        
        builder.insertNode(stored);
        builder.writeln();
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Image.CreateLinkedImage.doc");
      • insertOleObject

        public Shape insertOleObject(java.lang.String fileName, boolean isLinked, boolean asIcon, java.awt.image.BufferedImage presentation)
                             throws java.lang.Exception
        Inserts an embedded or linked OLE object from a file into the document. Detects OLE object type using file extension.
        Parameters:
        fileName - Full path to the file.
        isLinked - If true then linked OLE object is inserted otherwise embedded OLE object is inserted.
        asIcon - Specifies either Iconic or Normal mode of OLE object being inserted.
        presentation - Image presentation of OLE object. If value is null Aspose.Words will use one of the predefined images.
        Returns:
        Shape node containing Ole object and inserted at the current Builder position.

        Example:

        Shows how to insert an OLE object into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        BufferedImage representingImage = ImageIO.read(new File(getImageDir() + "Aspose.Words.gif"));
        
        Shape oleObject = builder.insertOleObject(getMyDir() + "Document.Spreadsheet.xlsx", false, false, representingImage);
        Shape oleObjectWithProgId = builder.insertOleObject(getMyDir() + "Document.Spreadsheet.xlsx", "Excel.Sheet", false, false, representingImage);
        
        doc.save(getMyDir() + "\\Artifacts\\Document.InsertedOleObject.docx");
      • insertOleObject

        public Shape insertOleObject(java.lang.String fileName, java.lang.String progId, boolean isLinked, boolean asIcon, java.awt.image.BufferedImage presentation)
                             throws java.lang.Exception
        Inserts an embedded or linked OLE object from a file into the document. Detects OLE object type using given progID parameter.
        Parameters:
        fileName - Full path to the file.
        progId - ProgId of OLE object.
        isLinked - If true then linked OLE object is inserted otherwise embedded OLE object is inserted.
        asIcon - Specifies either Iconic or Normal mode of OLE object being inserted.
        presentation - Image presentation of OLE object. If value is null Aspose.Words will use one of the predefined images.
        Returns:
        Shape node containing Ole object and inserted at the current Builder position.

        Example:

        Shows how to insert an OLE object into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        BufferedImage representingImage = ImageIO.read(new File(getImageDir() + "Aspose.Words.gif"));
        
        Shape oleObject = builder.insertOleObject(getMyDir() + "Document.Spreadsheet.xlsx", false, false, representingImage);
        Shape oleObjectWithProgId = builder.insertOleObject(getMyDir() + "Document.Spreadsheet.xlsx", "Excel.Sheet", false, false, representingImage);
        
        doc.save(getMyDir() + "\\Artifacts\\Document.InsertedOleObject.docx");
      • insertOnlineVideo

        public Shape insertOnlineVideo(java.lang.String videoUrl, double width, double height)
                               throws java.lang.Exception
        Inserts an online video object into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Insertion of online video from the following resources is supported:

        • https://www.youtube.com/
        • https://vimeo.com/

        If your online video is not displaying correctly, use insertOnlineVideo(java.lang.String,java.lang.String,byte[],double,double), which accepts custom embedded html code.

        The code for embedding video can vary between providers, consult your corresponding provider of choice for details.

        Parameters:
        videoUrl - The URL to the video.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        Returns:
        The image node that was just inserted.

        Example:

        Show how to insert online video into a document using video url
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Pass direct url from youtu.be.
        String url = "https://youtu.be/t_1LYZ102RA";
        
        double width = 360.0;
        double height = 270.0;
        
        builder.insertOnlineVideo(url, width, height);
      • insertOnlineVideo

        public Shape insertOnlineVideo(java.lang.String videoUrl, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                               throws java.lang.Exception
        Inserts an online video object into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Insertion of online video from the following resources is supported:

        • https://www.youtube.com/
        • https://vimeo.com/

        If your online video is not displaying correctly, use insertOnlineVideo(java.lang.String,java.lang.String,byte[],double,double), which accepts custom embedded html code.

        The code for embedding video can vary between providers, consult your corresponding provider of choice for details.

        Parameters:
        videoUrl - The URL to the video.
        horzPos - A RelativeHorizontalPosition value. Specifies where the distance to the image is measured from.
        left - Distance in points from the origin to the left side of the image.
        vertPos - A RelativeVerticalPosition value. Specifies where the distance to the image measured from.
        top - Distance in points from the origin to the top side of the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        wrapType - A WrapType value. Specifies how to wrap text around the image.
        Returns:
        The image node that was just inserted.
      • insertOnlineVideo

        public Shape insertOnlineVideo(java.lang.String videoUrl, java.lang.String videoEmbedCode, byte[] thumbnailImageBytes, double width, double height)
                               throws java.lang.Exception
        Inserts an online video object into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        videoUrl - The URL to the video.
        videoEmbedCode - The embed code for the video.
        thumbnailImageBytes - The thumbnail image bytes.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        Returns:
        The image node that was just inserted.

        Example:

        Show how to insert online video into a document using html code
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Shape width/height.
        double width = 360.0;
        double height = 270.0;
        
        // Poster frame image.
        String image = getImageDir() + "Test_636_852.gif";
        byte[] imageBytes = Files.readAllBytes(Paths.get(image));
        
        // Visible url
        String vimeoVideoUrl = "https://vimeo.com/52477838";
        
        // Embed Html code.
        String vimeoEmbedCode = "<iframe src=\"https://player.vimeo.com/video/52477838\" width=\"640\" height=\"360\" frameborder=\"0\" title=\"Aspose\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";
        
        builder.insertOnlineVideo(vimeoVideoUrl, vimeoEmbedCode, imageBytes, width, height);
      • insertOnlineVideo

        public Shape insertOnlineVideo(java.lang.String videoUrl, java.lang.String videoEmbedCode, byte[] thumbnailImageBytes, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                               throws java.lang.Exception
        Inserts an online video object into the document and scales it to the specified size.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Parameters:
        videoUrl - The URL to the video.
        videoEmbedCode - The embed code for the video.
        thumbnailImageBytes - The thumbnail image bytes.
        horzPos - A RelativeHorizontalPosition value. Specifies where the distance to the image is measured from.
        left - Distance in points from the origin to the left side of the image.
        vertPos - A RelativeVerticalPosition value. Specifies where the distance to the image measured from.
        top - Distance in points from the origin to the top side of the image.
        width - The width of the image in points. Can be a negative or zero value to request 100% scale.
        height - The height of the image in points. Can be a negative or zero value to request 100% scale.
        wrapType - A WrapType value. Specifies how to wrap text around the image.
        Returns:
        The image node that was just inserted.
      • insertParagraph

        public Paragraph insertParagraph()
        Inserts a paragraph break into the document.

        Current paragraph formatting specified by the ParagraphFormat property is used.

        Breaks the current paragraph in two. After inserting the paragraph, the cursor is placed at the beginning of the new paragraph.

        Returns:
        The paragraph node that was just inserted. It is the same node as CurrentParagraph.

        Example:

        Shows how to insert a paragraph into the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify font formatting
        Font font = builder.getFont();
        font.setSize(16);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Arial");
        font.setUnderline(Underline.DASH);
        
        // Specify paragraph formatting
        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
        paragraphFormat.setFirstLineIndent(8);
        paragraphFormat.setAlignment(ParagraphAlignment.JUSTIFY);
        paragraphFormat.setAddSpaceBetweenFarEastAndAlpha(true);
        paragraphFormat.setAddSpaceBetweenFarEastAndDigit(true);
        paragraphFormat.setKeepTogether(true);
        
        builder.writeln("A whole paragraph.");
      • insertShape

        public Shape insertShape(int shapeType, double width, double height)
                         throws java.lang.Exception
        Inserts inline shape with specified type and size.
        Parameters:
        shapeType - A ShapeType value. The shape type to insert into the document.
        width - The width of the shape in points.
        height - The height of the shape in points.
        Returns:
        The shape node that was inserted.
      • insertShape

        public Shape insertShape(int shapeType, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                         throws java.lang.Exception
        Inserts free-floating shape with specified position, size and text wrap type.
        Parameters:
        shapeType - A ShapeType value. The shape type to insert into the document
        horzPos - A RelativeHorizontalPosition value. Specifies where the horizontal distance to the shape is measured from.
        left - Distance in points from the origin to the left side of the shape.
        vertPos - A RelativeVerticalPosition value. Specifies where the vertical distance to the shape is measured from.
        top - Distance in points from the origin to the top side of the shape.
        width - The width of the shape in points.
        height - The width of the shape in points.
        wrapType - A WrapType value. Specifies how to wrap text around the shape.
        Returns:
        The shape node that was inserted.
      • insertSignatureLine

        public Shape insertSignatureLine(SignatureLineOptions signatureLineOptions)
                                 throws java.lang.Exception
        Inserts a signature line at the current position.
        Parameters:
        signatureLineOptions - The object that stores parameters of creating signature line.
        Returns:
        The signature line node that was just inserted.

        Example:

        Shows how to sign document with personal certificate and specific signatire line.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
        signatureLineOptions.setSigner("vderyushev");
        signatureLineOptions.setSignerTitle("QA");
        signatureLineOptions.setEmail("vderyushev@aspose.com");
        signatureLineOptions.setShowDate(true);
        signatureLineOptions.setDefaultInstructions(false);
        signatureLineOptions.setInstructions("You need more info about signature line");
        signatureLineOptions.setAllowComments(true);
        
        SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
        signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.SignatureLineProviderId In.docx");
        
        SignOptions signOptions = new SignOptions();
        signOptions.setSignatureLineId(signatureLine.getId());
        signOptions.setProviderId(signatureLine.getProviderId());
        signOptions.setComments("Document was signed by vderyushev");
        signOptions.setSignTime(new Date());
        
        CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        DigitalSignatureUtil.sign(getMyDir() + "\\Artifacts\\DocumentBuilder.SignatureLineProviderId In.docx", getMyDir() + "\\Artifacts\\DocumentBuilder.SignatureLineProviderId Out.docx", certHolder, signOptions);
      • insertSignatureLine

        public Shape insertSignatureLine(SignatureLineOptions signatureLineOptions, int horzPos, double left, int vertPos, double top, int wrapType)
                                 throws java.lang.Exception
        Inserts a signature line at the specified position.

        You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

        Aspose.Words will insert the image in the PNG format and with default settings. If you want to insert a BufferedImage in another format or with other settings, you need to save the image into a byte array and use insertImage(byte[]).

        Parameters:
        signatureLineOptions - The object that stores parameters of creating signature line.
        horzPos - A RelativeHorizontalPosition value. Specifies where the distance to the signature line is measured from.
        left - Distance in points from the origin to the left side of the signature line.
        vertPos - A RelativeVerticalPosition value. Specifies where the distance to the signature line measured from.
        top - Distance in points from the origin to the top side of the signature line.
        wrapType - A WrapType value. Specifies how to wrap text around the signature line.
        Returns:
        The signature line node that was just inserted.

        Example:

        Shows how to insert signature line at the specified position.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        SignatureLineOptions options = new SignatureLineOptions();
        options.setSigner("John Doe");
        options.setSignerTitle("Manager");
        options.setEmail("johndoe@aspose.com");
        options.setShowDate(true);
        options.setDefaultInstructions(false);
        options.setInstructions("You need more info about signature line");
        options.setAllowComments(true);
        
        builder.insertSignatureLine(options, RelativeHorizontalPosition.RIGHT_MARGIN, 2.0, RelativeVerticalPosition.PAGE, 3.0, WrapType.INLINE);
      • insertStyleSeparator

        public void insertStyleSeparator()
        Inserts style separator into the document. This method allows to apply different paragraph styles to two different parts of a text line.
      • insertTableOfContents

        public Field insertTableOfContents(java.lang.String switches)
        Inserts a TOC (table of contents) field into the document.

        This method inserts a TOC (table of contents) field into the document at the current position.

        A table of contents in a Word document can be built in a number of ways and formatted using a variety of options. The way the table is built and displayed by Microsoft Word is controlled by the field switches.

        The easiest way to specify the switches is to insert and configure a table of contents into a Word document using the Insert->Reference->Index and Tables menu, then switch display of field codes on to see the switches. You can press Alt+F9 in Microsoft Word to toggle display of field codes on or off.

        For example, after creating a table of contents, the following field is inserted into the document: { TOC \o "1-3" \h \z \u }. You can copy \o "1-3" \h \z \u and use it as the switches parameter.

        Note that InsertTableOfContents will only insert a TOC field, but will not actually build the table of contents. The table of contents is built by Microsoft Word when the field is updated.

        If you insert a table of contents using this method and then open the file in Microsoft Word, you will not see the table of contents because the TOC field has not yet been updated.

        In Microsoft Word, fields are not automatically updated when a document is opened, but you can update fields in a document at any time by pressing F9.

        Parameters:
        switches - The TOC field switches.

        Example:

        Demonstrates how to insert a Table of contents (TOC) into a document using heading styles as entries.
        // Use a blank document
        Document doc = new Document();
        // Create a document builder to insert content with into document.
        DocumentBuilder builder = new DocumentBuilder(doc);
        // Insert a table of contents at the beginning of the document.
        builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
        // Start the actual document content on the second page.
        builder.insertBreak(BreakType.PAGE_BREAK);
        // Build a document with complex structure by applying different heading styles thus creating TOC entries.
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        
        builder.writeln("Heading 1");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 1.1");
        builder.writeln("Heading 1.2");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        
        builder.writeln("Heading 2");
        builder.writeln("Heading 3");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 3.1");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_3);
        
        builder.writeln("Heading 3.1.1");
        builder.writeln("Heading 3.1.2");
        builder.writeln("Heading 3.1.3");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 3.2");
        builder.writeln("Heading 3.3");
        
        // Call the method below to update the TOC.
        doc.updateFields();
      • insertTextInput

        public FormField insertTextInput(java.lang.String name, int type, java.lang.String format, java.lang.String fieldValue, int maxLength)
                                 throws java.lang.Exception
        Inserts a text form field at the current position.

        If you specify a name for the form field, then a bookmark is automatically created with the same name.

        Parameters:
        name - The name of the form field. Can be an empty string.
        type - A TextFormFieldType value. Specifies the type of the text form field.
        format - Format string used to format the value of the form field.
        fieldValue - Text that will be shown in the field.
        maxLength - Maximum length the user can enter into the form field. Set to zero for unlimited length.
        Returns:
        The form field node that was just inserted.

        Example:

        Builds a sample form to fill.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Insert a text form field for input a name.
        builder.insertTextInput("", TextFormFieldType.REGULAR, "", "Enter your name here", 30);
        
        // Insert two blank lines.
        builder.writeln("");
        builder.writeln("");
        
        String[] items = new String[]{"-- Select your favorite footwear --", "Sneakers", "Oxfords", "Flip-flops", "Other", "I prefer to be barefoot"};
        
        // Insert a combo box to select a footwear type.
        builder.insertComboBox("", items, 0);
        
        // Insert two blank lines.
        builder.writeln("");
        builder.writeln("");
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateForm.doc");

        Example:

        Shows how to insert form fields, set options and gather them back in for use
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a text input field. The unique name of this field is "TextInput1", the other parameters define
        // what type of FormField it is, the format of the text, the field result and the maximum text length (0 = no limit)
        builder.insertTextInput("TextInput1", TextFormFieldType.REGULAR, "", "", 0);

        Example:

        Shows how to insert a text input form field into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertTextInput("TextInput", TextFormFieldType.REGULAR, "", "Hello", 0);
      • moveTo

        public void moveTo(Node node)
        Moves the cursor to an inline node or to the end of a paragraph.

        When node is an inline-level node, the cursor is moved to this node and further content will be inserted before that node.

        When node is a Paragraph, the cursor is moved to the end of the paragraph and further content will be inserted just before the paragraph break.

        When node is a block-level node but not a Paragraph, the cursor is moved to the end of the first paragraph into block-level node and further content will be inserted just before the paragraph break.

        Parameters:
        node - The node must be a paragraph or a direct child of a paragraph.

        Example:

        Shows how to move between nodes and manipulate current ones.
        Document doc = new Document(getMyDir() + "DocumentBuilder.WorkingWithNodes.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Move to a bookmark and delete the parent paragraph.
        builder.moveToBookmark("ParaToDelete");
        builder.getCurrentParagraph().remove();
        
        FindReplaceOptions options = new FindReplaceOptions();
        options.setMatchCase(false);
        options.setFindWholeWordsOnly(true);
        
        // Move to a particular paragraph's run and replace all occurrences of "bad" with "good" within this run.
        builder.moveTo(doc.getLastSection().getBody().getParagraphs().get(0).getRuns().get(0));
        builder.getCurrentNode().getRange().replace("bad", "good", options);
        
        // Mark the beginning of the document.
        builder.moveToDocumentStart();
        builder.writeln("Start of document.");
        
        // Mark the ending of the document.
        builder.moveToDocumentEnd();
        builder.writeln("End of document.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.WorkingWithNodes.doc");

        Example:

        Shows how to move a cursor position to a specified node.
        Document doc = new Document(getMyDir() + "DocumentBuilder.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.moveTo(doc.getFirstSection().getBody().getLastParagraph());
      • moveToBookmark

        public boolean moveToBookmark(java.lang.String bookmarkName)
                              throws java.lang.Exception
        Moves the cursor to a bookmark.

        Moves the cursor to a position just after the start of the bookmark with the specified name.

        The comparison is not case-sensitive. If the bookmark was not found, false is returned and the cursor is not moved.

        Inserting new text does not replace existing text of the bookmark.

        Note that some bookmarks in the document are assigned to form fields. Moving to such a bookmark and inserting text there inserts the text into the form field code. Although this will not invalidate the form field, the inserted text will not be visible because it becomes part of the field code.

        Parameters:
        bookmarkName - The name of the bookmark to move the cursor to.
        Returns:
        True if the bookmark was found; false otherwise.

        Example:

        Shows how to move between nodes and manipulate current ones.
        Document doc = new Document(getMyDir() + "DocumentBuilder.WorkingWithNodes.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Move to a bookmark and delete the parent paragraph.
        builder.moveToBookmark("ParaToDelete");
        builder.getCurrentParagraph().remove();
        
        FindReplaceOptions options = new FindReplaceOptions();
        options.setMatchCase(false);
        options.setFindWholeWordsOnly(true);
        
        // Move to a particular paragraph's run and replace all occurrences of "bad" with "good" within this run.
        builder.moveTo(doc.getLastSection().getBody().getParagraphs().get(0).getRuns().get(0));
        builder.getCurrentNode().getRange().replace("bad", "good", options);
        
        // Mark the beginning of the document.
        builder.moveToDocumentStart();
        builder.writeln("Start of document.");
        
        // Mark the ending of the document.
        builder.moveToDocumentEnd();
        builder.writeln("End of document.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.WorkingWithNodes.doc");
      • moveToBookmark

        public boolean moveToBookmark(java.lang.String bookmarkName, boolean isStart, boolean isAfter)
                              throws java.lang.Exception
        Moves the cursor to a bookmark with greater precision.

        Moves the cursor to a position before or after the bookmark start or end.

        If desired position is not at inline level, moves to the next paragraph.

        The comparison is not case-sensitive. If the bookmark was not found, false is returned and the cursor is not moved.

        Parameters:
        bookmarkName - The name of the bookmark to move the cursor to.
        isStart - When true, moves the cursor to the beginning of the bookmark. When false, moves the cursor to the end of the bookmark.
        isAfter - When true, moves the cursor to be after the bookmark start or end position. When false, moves the cursor to be before the bookmark start or end position.
        Returns:
        True if the bookmark was found; false otherwise.

        Example:

        Shows how to move a cursor position to just after the bookmark end.
        Document doc = new Document(getMyDir() + "DocumentBuilder.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.moveToBookmark("CoolBookmark", false, true);
        builder.writeln("This is a very cool bookmark.");
      • moveToCell

        public void moveToCell(int tableIndex, int rowIndex, int columnIndex, int characterIndex)
        Moves the cursor to a table cell in the current section.

        The navigation is performed inside the current story of the current section.

        For the index parameters, when index is greater than or equal to 0, it specifies an index from the beginning with 0 being the first element. When index is less than 0, it specified an index from the end with -1 being the last element.

        Parameters:
        tableIndex - The index of the table to move to.
        rowIndex - The index of the row in the table.
        columnIndex - The index of the column in the table.
        characterIndex - The index of the character inside the cell. Currently can only specify 0 to move to the beginning of the cell or -1 to move to the end of the cell.

        Example:

        Shows how to move a cursor position to the specified table cell.
        Document doc = new Document(getMyDir() + "DocumentBuilder.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // All parameters are 0-index. Moves to the 2nd table, 3rd row, 5th cell.
        builder.moveToCell(1, 2, 4, 0);
        builder.writeln("Hello World!");
      • moveToDocumentEnd

        public void moveToDocumentEnd()
        Moves the cursor to the end of the document.

        Example:

        Shows how to move between nodes and manipulate current ones.
        Document doc = new Document(getMyDir() + "DocumentBuilder.WorkingWithNodes.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Move to a bookmark and delete the parent paragraph.
        builder.moveToBookmark("ParaToDelete");
        builder.getCurrentParagraph().remove();
        
        FindReplaceOptions options = new FindReplaceOptions();
        options.setMatchCase(false);
        options.setFindWholeWordsOnly(true);
        
        // Move to a particular paragraph's run and replace all occurrences of "bad" with "good" within this run.
        builder.moveTo(doc.getLastSection().getBody().getParagraphs().get(0).getRuns().get(0));
        builder.getCurrentNode().getRange().replace("bad", "good", options);
        
        // Mark the beginning of the document.
        builder.moveToDocumentStart();
        builder.writeln("Start of document.");
        
        // Mark the ending of the document.
        builder.moveToDocumentEnd();
        builder.writeln("End of document.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.WorkingWithNodes.doc");
      • moveToDocumentStart

        public void moveToDocumentStart()
        Moves the cursor to the beginning of the document.

        Example:

        Shows how to move between nodes and manipulate current ones.
        Document doc = new Document(getMyDir() + "DocumentBuilder.WorkingWithNodes.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Move to a bookmark and delete the parent paragraph.
        builder.moveToBookmark("ParaToDelete");
        builder.getCurrentParagraph().remove();
        
        FindReplaceOptions options = new FindReplaceOptions();
        options.setMatchCase(false);
        options.setFindWholeWordsOnly(true);
        
        // Move to a particular paragraph's run and replace all occurrences of "bad" with "good" within this run.
        builder.moveTo(doc.getLastSection().getBody().getParagraphs().get(0).getRuns().get(0));
        builder.getCurrentNode().getRange().replace("bad", "good", options);
        
        // Mark the beginning of the document.
        builder.moveToDocumentStart();
        builder.writeln("Start of document.");
        
        // Mark the ending of the document.
        builder.moveToDocumentEnd();
        builder.writeln("End of document.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.WorkingWithNodes.doc");
      • moveToField

        public void moveToField(Field field, boolean isAfter)
                        throws java.lang.Exception
        Moves the cursor to a field in the document.
        Parameters:
        field - The field to move the cursor to.
        isAfter - When true, moves the cursor to be after the field end. When false, moves the cursor to be before the field start.

        Example:

        Shows how to move document builder's cursor to a specific field.
        Document doc = new Document(getMyDir() + "Document.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Field field = builder.insertField("MERGEFIELD field");
        
        builder.moveToField(field, true);
      • moveToHeaderFooter

        public void moveToHeaderFooter(int headerFooterType)
        Moves the cursor to the beginning of a header or footer in the current section.

        After you moved the cursor into a header or footer, you can use the rest of DocumentBuilder methods to modify the contents of the header or footer.

        If you want to create headers and footers different for the first page, you need to set PageSetup.DifferentFirstPageHeaderFooter.

        If you want to create headers and footers different for even and odd pages, you need to set PageSetup.OddAndEvenPagesHeaderFooter.

        Use moveToSection(int) to move out of the header into the main text.

        Parameters:
        headerFooterType - A HeaderFooterType value. Specifies the header or footer to move to.

        Example:

        Creates headers and footers in a document using DocumentBuilder.
        // Create a blank document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want headers and footers different for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header First");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header Even");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header Odd");
        
        // Create three pages in the document.
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.HeadersAndFooters.doc");

        Example:

        Inserts a watermark image into a document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // The best place for the watermark image is in the header or footer so it is shown on every page.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        
        BufferedImage image = ImageIO.read(new File(getImageDir() + "Watermark.png"));
        
        // Insert a floating picture.
        Shape shape = builder.insertImage(image);
        shape.setWrapType(WrapType.NONE);
        shape.setBehindText(true);
        
        shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        
        // Calculate image left and top position so it appears in the centre of the page.
        shape.setLeft((builder.getPageSetup().getPageWidth() - shape.getWidth()) / 2);
        shape.setTop((builder.getPageSetup().getPageHeight() - shape.getHeight()) / 2);
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertWatermark.doc");
      • moveToMergeField

        public boolean moveToMergeField(java.lang.String fieldName)
                                throws java.lang.Exception
        Moves the cursor to a position just beyond the specified merge field and removes the merge field.

        Note that this method deletes the merge field from the document after moving the cursor.

        Parameters:
        fieldName - The case-insensitive name of the mail merge field.
        Returns:
        True if the merge field was found and the cursor was moved; false otherwise.

        Example:

        Shows how to insert checkbox form fields into a document during mail merge.
        // File 'MailMerge.InsertCheckBox.doc' is a template
        // containing the table with the following fields in it:
        // <<TableStart:StudentCourse>> <<CourseName>> <<TableEnd:StudentCourse>>.
        
        public void mailMergeInsertCheckBox() throws Exception
        {
            Document doc = new Document(getMyDir() + "MailMerge.InsertCheckBox.doc");
        
            // Add a handler for the MergeField event.
            doc.getMailMerge().setFieldMergingCallback(new HandleMergeFieldInsertCheckBox());
        
            // Execute mail merge with regions.
            DataTable dataTable = getStudentCourseDataTable();
            doc.getMailMerge().executeWithRegions(dataTable);
        
            // Save resulting document with a new name.
            doc.save(getMyDir() + "\\Artifacts\\MailMerge.InsertCheckBox.doc");
        }
        
        private class HandleMergeFieldInsertCheckBox implements IFieldMergingCallback
        {
            /**
             * This is called for each merge field in the document
             * when Document.MailMerge.ExecuteWithRegions is called.
             */
            public void fieldMerging(FieldMergingArgs e) throws Exception
            {
                if (e.getDocumentFieldName().equals("CourseName"))
                {
                    // Insert the checkbox for this merge field, using DocumentBuilder.
                    DocumentBuilder builder = new DocumentBuilder(e.getDocument());
                    builder.moveToMergeField(e.getFieldName());
                    builder.insertCheckBox(e.getDocumentFieldName() + Integer.toString(mCheckBoxCount), false, 0);
                    builder.write((String) e.getFieldValue());
                    mCheckBoxCount++;
                }
            }
        
            public void imageFieldMerging(ImageFieldMergingArgs args)
            {
                // Do nothing.
            }
        
            /**
             * Counter for CheckBox name generation
             */
            private int mCheckBoxCount;
        }
        
        /**
         * Create DataTable and fill it with data.
         * In real life this DataTable should be filled from a database.
         */
        private static DataTable getStudentCourseDataTable() throws Exception
        {
            DataTable dataTable = new DataTable("StudentCourse");
            dataTable.getColumns().add("CourseName");
            for (int i = 0; i < 10; i++)
            {
                DataRow datarow = dataTable.newRow();
                dataTable.getRows().add(datarow);
                datarow.set(0, "Course " + Integer.toString(i));
            }
            return dataTable;
        }

        Example:

        Fills document merge fields with some data.
        Document doc = new Document(getMyDir() + "DocumentBuilder.FillingDocument.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.moveToMergeField("TeamLeaderName");
        builder.setBold(true);
        builder.writeln("Roman Korchagin");
        
        builder.moveToMergeField("SoftwareDeveloper1Name");
        builder.setItalic(true);
        builder.writeln("Dmitry Vorobyev");
        
        builder.moveToMergeField("SoftwareDeveloper2Name");
        builder.setItalic(true);
        builder.writeln("Vladimir Averkin");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.FillingDocument.doc");
      • moveToMergeField

        public boolean moveToMergeField(java.lang.String fieldName, boolean isAfter, boolean isDeleteField)
                                throws java.lang.Exception
        Moves the merge field to the specified merge field.
        Parameters:
        fieldName - The case-insensitive name of the mail merge field.
        isAfter - When true, moves the cursor to be after the field end. When false, moves the cursor to be before the field start.
        isDeleteField - When true, deletes the merge field.
        Returns:
        True if the merge field was found and the cursor was moved; false otherwise.
      • moveToParagraph

        public void moveToParagraph(int paragraphIndex, int characterIndex)
        Moves the cursor to a paragraph in the current section.

        The navigation is performed inside the current story of the current section. That is, if you moved the cursor to the primary header of the first section, then paragraphIndex specified the index of the paragraph inside that header of that section.

        When paragraphIndex is greater than or equal to 0, it specifies an index from the beginning of the section with 0 being the first paragraph. When paragraphIndex is less than 0, it specified an index from the end of the section with -1 being the last paragraph.

        Parameters:
        paragraphIndex - The index of the paragraph to move to.
        characterIndex - The index of the character inside the paragraph. Currently can only specify 0 to move to the beginning of the paragraph or -1 to move to the end of the paragraph.

        Example:

        Shows how to move a cursor position to the specified paragraph.
        Document doc = new Document(getMyDir() + "DocumentBuilder.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Parameters are 0-index. Moves to third paragraph.
        builder.moveToParagraph(2, 0);
        builder.writeln("This is the 3rd paragraph.");
      • moveToSection

        public void moveToSection(int sectionIndex)
        Moves the cursor to the beginning of the body in a specified section.

        When sectionIndex is greater than or equal to 0, it specifies an index from the beginning of the document with 0 being the first section. When sectionIndex is less than 0, it specified an index from the end of the document with -1 being the last section.

        The cursor is moved to the first paragraph in the Body of the specified section.

        Parameters:
        sectionIndex - The index of the section to move to.

        Example:

        Creates headers and footers in a document using DocumentBuilder.
        // Create a blank document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want headers and footers different for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header First");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header Even");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header Odd");
        
        // Create three pages in the document.
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.HeadersAndFooters.doc");
      • popFont

        public void popFont()
        Retrieves character formatting previously saved on the stack.
        See Also:
        Font, pushFont()

        Example:

        Shows how to use temporarily save and restore character formatting when building a document with DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set up font formatting and write text that goes before the hyperlink.
        builder.getFont().setName("Arial");
        builder.getFont().setSize(24);
        builder.getFont().setBold(true);
        builder.write("To go to an important location, click ");
        
        // Save the font formatting so we use different formatting for hyperlink and restore old formatting later.
        builder.pushFont();
        
        // Set new font formatting for the hyperlink and insert the hyperlink.
        // The "Hyperlink" style is a Microsoft Word built-in style so we don't have to worry to
        // create it, it will be created automatically if it does not yet exist in the document.
        builder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
        builder.insertHyperlink("here", "http://www.google.com", false);
        
        // Restore the formatting that was before the hyperlink.
        builder.popFont();
        
        builder.writeln(". We hope you enjoyed the example.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.PushPopFont.doc");
      • pushFont

        public void pushFont()
        Saves current character formatting onto the stack.
        See Also:
        Font, popFont()

        Example:

        Shows how to use temporarily save and restore character formatting when building a document with DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set up font formatting and write text that goes before the hyperlink.
        builder.getFont().setName("Arial");
        builder.getFont().setSize(24);
        builder.getFont().setBold(true);
        builder.write("To go to an important location, click ");
        
        // Save the font formatting so we use different formatting for hyperlink and restore old formatting later.
        builder.pushFont();
        
        // Set new font formatting for the hyperlink and insert the hyperlink.
        // The "Hyperlink" style is a Microsoft Word built-in style so we don't have to worry to
        // create it, it will be created automatically if it does not yet exist in the document.
        builder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
        builder.insertHyperlink("here", "http://www.google.com", false);
        
        // Restore the formatting that was before the hyperlink.
        builder.popFont();
        
        builder.writeln(". We hope you enjoyed the example.");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.PushPopFont.doc");
      • startBookmark

        public BookmarkStart startBookmark(java.lang.String bookmarkName)
        Marks the current position in the document as a bookmark start.

        Bookmarks in a document can overlap and span any range. To create a valid bookmark you need to call both startBookmark(java.lang.String) and endBookmark(java.lang.String) with the same bookmarkName parameter.

        Badly formed bookmarks or bookmarks with duplicate names will be ignored when the document is saved.

        Parameters:
        bookmarkName - Name of the bookmark.
        Returns:
        The bookmark start node that was just created.

        Example:

        Inserts a hyperlink referencing local bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startBookmark("Bookmark1");
        builder.write("Bookmarked text.");
        builder.endBookmark("Bookmark1");
        
        builder.writeln("Some other text");
        
        // Specify font formatting for the hyperlink.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        
        // Insert hyperlink.
        // Switch \o is used to provide hyperlink tip text.
        builder.insertHyperlink("Hyperlink Text", "Bookmark1\" \\o \"Hyperlink Tip", true);
        
        // Clear hyperlink formatting.
        builder.getFont().clearFormatting();
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertHyperlinkToLocalBookmark.doc");

        Example:

        Adds some text into the document and encloses the text in a bookmark using DocumentBuilder.
        DocumentBuilder builder = new DocumentBuilder();
        
        builder.startBookmark("MyBookmark");
        builder.writeln("Text inside a bookmark.");
        builder.endBookmark("MyBookmark");
      • startEditableRange

        public EditableRangeStart startEditableRange()
        Marks the current position in the document as an editable range start.

        Editable range in a document can overlap and span any range. To create a valid editable range you need to call both startEditableRange() and endEditableRange() or endEditableRange(com.aspose.words.EditableRangeStart) methods.

        Badly formed editable range will be ignored when the document is saved.

        Returns:
        The editable range start node that was just created.

        Example:

        Shows how to start and end an editable range.
        Document doc = new Document(getMyDir() + "Document.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Start an editable range.
        EditableRangeStart edRange1Start = builder.startEditableRange();
        
        // An EditableRange object is created for the EditableRangeStart that we just made.
        EditableRange editableRange1 = edRange1Start.getEditableRange();
        
        // Put something inside the editable range.
        builder.writeln("Paragraph inside first editable range");
        
        // An editable range is well-formed if it has a start and an end. 
        // Multiple editable ranges can be nested and overlapping. 
        EditableRangeEnd edRange1End = builder.endEditableRange();
        
        // Both the start and end automatically belong to editableRange1.
        System.out.println(editableRange1.getEditableRangeStart().equals(edRange1Start)); // True
        System.out.println(editableRange1.getEditableRangeEnd().equals(edRange1End)); // True
        
        // Explicitly state which EditableRangeStart a new EditableRangeEnd should be paired with.
        EditableRangeStart edRange2Start = builder.startEditableRange();
        builder.writeln("Paragraph inside second editable range");
        EditableRange editableRange2 = edRange2Start.getEditableRange();
        EditableRangeEnd edRange2End = builder.endEditableRange(edRange2Start);
        
        // Both the start and end automatically belong to editableRange2.
        System.out.println(editableRange2.getEditableRangeStart().equals(edRange2Start)); // True
        System.out.println(editableRange2.getEditableRangeEnd().equals(edRange2End)); // True
      • startTable

        public Table startTable()
        Starts a table in the document.

        The next method to call is insertCell().

        This method starts a nested table when called inside a cell.

        Returns:
        The table node that was just created.

        Example:

        Shows how to build a formatted table that contains 2 rows and 2 columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Insert a cell
        builder.insertCell();
        // Use fixed column widths.
        table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
        
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("This is row 1 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.write("This is row 1 cell 2");
        
        builder.endRow();
        
        // Insert a cell
        builder.insertCell();
        
        // Apply new row formatting
        builder.getRowFormat().setHeight(100);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.writeln("This is row 2 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.writeln("This is row 2 cell 2");
        
        builder.endRow();
        
        builder.endTable();

        Example:

        Shows how to create a table that contains a single formatted cell.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        builder.insertCell();
        
        // Set the cell formatting
        CellFormat cellFormat = builder.getCellFormat();
        cellFormat.setWidth(250);
        cellFormat.setLeftPadding(30);
        cellFormat.setRightPadding(30);
        cellFormat.setTopPadding(30);
        cellFormat.setBottomPadding(30);
        
        builder.writeln("I'm a wonderful formatted cell.");
        
        builder.endRow();
        builder.endTable();
      • write

        public void write(java.lang.String text)
        Inserts a string into the document at the current insert position. Current font formatting specified by the Font property is used.
        Parameters:
        text - The string to insert into the document.

        Example:

        Shows how to create a formatted table using DocumentBuilder
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Make the header row.
        builder.insertCell();
        
        // Set the left indent for the table. Table wide formatting must be applied after
        // at least one row is present in the table.
        table.setLeftIndent(20.0);
        
        // Set height and define the height rule for the header row.
        builder.getRowFormat().setHeight(40.0);
        builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);
        
        // Some special features for the header row.
        builder.getCellFormat().getShading().setBackgroundPatternColor(new Color(198, 217, 241));
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        builder.getFont().setSize(16);
        builder.getFont().setName("Arial");
        builder.getFont().setBold(true);
        
        builder.getCellFormat().setWidth(100.0);
        builder.write("Header Row,\n Cell 1");
        
        // We don't need to specify the width of this cell because it's inherited from the previous cell.
        builder.insertCell();
        builder.write("Header Row,\n Cell 2");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Header Row,\n Cell 3");
        builder.endRow();
        
        // Set features for the other rows and cells.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
        builder.getCellFormat().setWidth(100.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        
        // Reset height and define a different height rule for table body
        builder.getRowFormat().setHeight(30.0);
        builder.getRowFormat().setHeightRule(HeightRule.AUTO);
        builder.insertCell();
        // Reset font formatting.
        builder.getFont().setSize(12);
        builder.getFont().setBold(false);
        
        // Build the other cells.
        builder.write("Row 1, Cell 1 Content");
        builder.insertCell();
        builder.write("Row 1, Cell 2 Content");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Row 1, Cell 3 Content");
        builder.endRow();
        
        builder.insertCell();
        builder.getCellFormat().setWidth(100.0);
        builder.write("Row 2, Cell 1 Content");
        
        builder.insertCell();
        builder.write("Row 2, Cell 2 Content");
        
        builder.insertCell();
        builder.getCellFormat().setWidth(200.0);
        builder.write("Row 2, Cell 3 Content.");
        builder.endRow();
        builder.endTable();
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateFormattedTable.doc");

        Example:

        Shows how to build a formatted table that contains 2 rows and 2 columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Insert a cell
        builder.insertCell();
        // Use fixed column widths.
        table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
        
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("This is row 1 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.write("This is row 1 cell 2");
        
        builder.endRow();
        
        // Insert a cell
        builder.insertCell();
        
        // Apply new row formatting
        builder.getRowFormat().setHeight(100);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.writeln("This is row 2 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.writeln("This is row 2 cell 2");
        
        builder.endRow();
        
        builder.endTable();

        Example:

        Shows how to create a simple table using DocumentBuilder with default formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // We call this method to start building the table.
        builder.startTable();
        builder.insertCell();
        builder.write("Row 1, Cell 1 Content.");
        
        // Build the second cell
        builder.insertCell();
        builder.write("Row 1, Cell 2 Content.");
        // Call the following method to end the row and start a new row.
        builder.endRow();
        
        // Build the first cell of the second row.
        builder.insertCell();
        builder.write("Row 2, Cell 1 Content");
        
        // Build the second cell.
        builder.insertCell();
        builder.write("Row 2, Cell 2 Content.");
        builder.endRow();
        
        // Signal that we have finished building the table.
        builder.endTable();
        
        // Save the document to disk.
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.CreateSimpleTable.doc");

        Example:

        Inserts a String surrounded by a border into a document.
        DocumentBuilder builder = new DocumentBuilder();
        
        builder.getFont().getBorder().setColor(Color.GREEN);
        builder.getFont().getBorder().setLineWidth(2.5);
        builder.getFont().getBorder().setLineStyle(LineStyle.DASH_DOT_STROKER);
        
        builder.write("run of text in a green border");
      • writeln

        public void writeln()
        Inserts a paragraph break into the document.

        Calls insertParagraph().

        Example:

        Creates headers and footers in a document using DocumentBuilder.
        // Create a blank document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want headers and footers different for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header First");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header Even");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header Odd");
        
        // Create three pages in the document.
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.HeadersAndFooters.doc");
      • writeln

        public void writeln(java.lang.String text)
        Inserts a string and a paragraph break into the document. Current font and paragraph formatting specified by the Font and ParagraphFormat properties are used.
        Parameters:
        text - The string to insert into the document.

        Example:

        Shows how to build a formatted table that contains 2 rows and 2 columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        
        // Insert a cell
        builder.insertCell();
        // Use fixed column widths.
        table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
        
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("This is row 1 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.write("This is row 1 cell 2");
        
        builder.endRow();
        
        // Insert a cell
        builder.insertCell();
        
        // Apply new row formatting
        builder.getRowFormat().setHeight(100);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.writeln("This is row 2 cell 1");
        
        // Insert a cell
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.writeln("This is row 2 cell 2");
        
        builder.endRow();
        
        builder.endTable();