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:

Shows how to use a document builder to create a table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Start the table, then populate the first row with two cells.
builder.startTable();
builder.insertCell();
builder.write("Row 1, Cell 1.");
builder.insertCell();
builder.write("Row 1, Cell 2.");

// Call the builder's "EndRow" method to start a new row.
builder.endRow();
builder.insertCell();
builder.write("Row 2, Cell 1.");
builder.insertCell();
builder.write("Row 2, Cell 2.");
builder.endTable();

doc.save(getArtifactsDir() + "DocumentBuilder.CreateTable.docx");

Example:

Shows how to create headers and footers in a document using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Specify that we want different headers and footers for first, even and odd pages.
builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);

// Create the headers, then add three pages to the document to display each header type.
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
builder.write("Header for the first page");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.write("Header for even pages");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.write("Header for all other pages");

builder.moveToSection(0);
builder.writeln("Page1");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page2");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page3");

doc.save(getArtifactsDir() + "DocumentBuilder.HeadersAndFooters.docx");

Example:

Shows how to build a table with custom borders.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.startTable();

// Setting table formatting options for a document builder
// will apply them to every row and cell that we add with it.
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

builder.getCellFormat().clearFormatting();
builder.getCellFormat().setWidth(150.0);
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
builder.getCellFormat().setWrapText(false);
builder.getCellFormat().setFitText(true);

builder.getRowFormat().clearFormatting();
builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
builder.getRowFormat().setHeight(50.0);
builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D);
builder.getRowFormat().getBorders().setColor(Color.ORANGE);

builder.insertCell();
builder.write("Row 1, Col 1");

builder.insertCell();
builder.write("Row 1, Col 2");
builder.endRow();

// Changing the formatting will apply it to the current cell,
// and any new cells that we create with the builder afterward.
// This will not affect the cells that we have added previously.
builder.getCellFormat().getShading().clearFormatting();

builder.insertCell();
builder.write("Row 2, Col 1");

builder.insertCell();
builder.write("Row 2, Col 2");

builder.endRow();

// Increase row height to fit the vertical text.
builder.insertCell();
builder.getRowFormat().setHeight(150.0);
builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
builder.write("Row 3, Col 1");

builder.insertCell();
builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
builder.write("Row 3, Col 2");

builder.endRow();
builder.endTable();

doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");

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.
BookmarkEndendColumnBookmark(java.lang.String bookmarkName)
Marks the current position in the document as a column bookmark end. The position must be in a table cell.
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 a document at the cursor position.
NodeinsertDocument(Document srcDoc, int importFormatMode, ImportFormatOptions importFormatOptions)
Inserts a document at the cursor position.
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.
ShapeinsertHorizontalRule()
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.
voidinsertHtml(java.lang.String html, int options)
Inserts an HTML string into the document. Allows to specify additional options.
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.
ShapeinsertOleObjectAsIcon(java.lang.String fileName, boolean isLinked, java.lang.String iconFile, java.lang.String iconCaption)
Inserts an embedded or linked OLE object as icon into the document. Allows to specify icon file and caption. Detects OLE object type using file extension.
ShapeinsertOleObjectAsIcon(java.lang.String fileName, java.lang.String progId, boolean isLinked, java.lang.String iconFile, java.lang.String iconCaption)
Inserts an embedded or linked OLE object as icon into the document. Allows to specify icon file and caption. 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.
BookmarkStartstartColumnBookmark(java.lang.String bookmarkName)
Marks the current position in the document as a column bookmark start. The position must be in a table cell.
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:

        Shows how to insert formatted text using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify font formatting, then add text.
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Courier New");
        font.setUnderline(Underline.DASH);
        
        builder.write("Hello world!");
      • 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:

        Shows how to insert a Table of contents (TOC) into a document using heading styles as entries.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a table of contents for the first page of the document.
        // Configure the table to pick up paragraphs with headings of levels 1 to 3.
        // Also, set its entries to be hyperlinks that will take us
        // to the location of the heading when left-clicked in Microsoft Word.
        builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // Populate the table of contents by adding paragraphs with heading styles.
        // Each such heading with a level between 1 and 3 will create an entry in the table.
        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_4);
        builder.writeln("Heading 3.1.3.1");
        builder.writeln("Heading 3.1.3.2");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        builder.writeln("Heading 3.2");
        builder.writeln("Heading 3.3");
        
        // A table of contents is a field of a type that needs to be updated to show an up-to-date result.
        doc.updateFields();
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertToc.docx");

        Example:

        Shows how to create headers and footers in a document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want different headers and footers for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers, then add three pages to the document to display each header type.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header for the first page");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header for even pages");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header for all other pages");
        
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.HeadersAndFooters.docx");
    • Property Getters/Setters Detail

      • getBold/setBold

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

        Example:

        Shows how to fill MERGEFIELDs with data with a document builder instead of a mail merge.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert some MERGEFIELDS, which accept data from columns of the same name in a data source during a mail merge,
        // and then fill them manually.
        builder.insertField(" MERGEFIELD Chairman ");
        builder.insertField(" MERGEFIELD ChiefFinancialOfficer ");
        builder.insertField(" MERGEFIELD ChiefTechnologyOfficer ");
        
        builder.moveToMergeField("Chairman");
        builder.setBold(true);
        builder.writeln("John Doe");
        
        builder.moveToMergeField("ChiefFinancialOfficer");
        builder.setItalic(true);
        builder.writeln("Jane Doe");
        
        builder.moveToMergeField("ChiefTechnologyOfficer");
        builder.setItalic(true);
        builder.writeln("John Bloggs");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.FillMergeFields.docx");
      • getCellFormat

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

        Example:

        Shows how to build a table with custom borders.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        
        // Setting table formatting options for a document builder
        // will apply them to every row and cell that we add with it.
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        
        builder.getCellFormat().clearFormatting();
        builder.getCellFormat().setWidth(150.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.getCellFormat().setWrapText(false);
        builder.getCellFormat().setFitText(true);
        
        builder.getRowFormat().clearFormatting();
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getRowFormat().setHeight(50.0);
        builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D);
        builder.getRowFormat().getBorders().setColor(Color.ORANGE);
        
        builder.insertCell();
        builder.write("Row 1, Col 1");
        
        builder.insertCell();
        builder.write("Row 1, Col 2");
        builder.endRow();
        
        // Changing the formatting will apply it to the current cell,
        // and any new cells that we create with the builder afterward.
        // This will not affect the cells that we have added previously.
        builder.getCellFormat().getShading().clearFormatting();
        
        builder.insertCell();
        builder.write("Row 2, Col 1");
        
        builder.insertCell();
        builder.write("Row 2, Col 2");
        
        builder.endRow();
        
        // Increase row height to fit the vertical text.
        builder.insertCell();
        builder.getRowFormat().setHeight(150.0);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 3, Col 1");
        
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 3, Col 2");
        
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");

        Example:

        Shows how to format cells with a document builder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Row 1, cell 1.");
        
        // Insert a second cell, and then configure cell text padding options.
        // The builder will apply these settings at its current cell, and any new cells creates afterwards.
        builder.insertCell();
        
        CellFormat cellFormat = builder.getCellFormat();
        cellFormat.setWidth(250.0);
        cellFormat.setLeftPadding(30.0);
        cellFormat.setRightPadding(30.0);
        cellFormat.setTopPadding(30.0);
        cellFormat.setBottomPadding(30.0);
        
        builder.write("Row 1, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // The first cell was unaffected by the padding reconfiguration, and still holds the default values.
        Assert.assertEquals(0.0d, table.getFirstRow().getCells().get(0).getCellFormat().getWidth());
        Assert.assertEquals(5.4d, table.getFirstRow().getCells().get(0).getCellFormat().getLeftPadding());
        Assert.assertEquals(5.4d, table.getFirstRow().getCells().get(0).getCellFormat().getRightPadding());
        Assert.assertEquals(0.0d, table.getFirstRow().getCells().get(0).getCellFormat().getTopPadding());
        Assert.assertEquals(0.0d, table.getFirstRow().getCells().get(0).getCellFormat().getBottomPadding());
        
        Assert.assertEquals(250.0d, table.getFirstRow().getCells().get(1).getCellFormat().getWidth());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getLeftPadding());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getRightPadding());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getTopPadding());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getBottomPadding());
        
        // The first cell will still grow in the output document to match the size of its neighboring cell.
        doc.save(getArtifactsDir() + "DocumentBuilder.SetCellFormatting.docx");

        Example:

        Shows how to build a formatted 2x2 table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("Row 1, cell 1.");
        builder.insertCell();
        builder.write("Row 1, cell 2.");
        builder.endRow();
        
        // While building the table, the document builder will apply its current RowFormat/CellFormat property values
        // to the current row/cell that its cursor is in and any new rows/cells as it creates them.
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(0).getCellFormat().getVerticalAlignment());
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(1).getCellFormat().getVerticalAlignment());
        
        builder.insertCell();
        builder.getRowFormat().setHeight(100.0);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 2, cell 1.");
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 2, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
        Assert.assertEquals(0.0, table.getRows().get(0).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.AUTO, table.getRows().get(0).getRowFormat().getHeightRule());
        Assert.assertEquals(100.0, table.getRows().get(1).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.EXACTLY, table.getRows().get(1).getRowFormat().getHeightRule());
        Assert.assertEquals(TextOrientation.UPWARD, table.getRows().get(1).getCells().get(0).getCellFormat().getOrientation());
        Assert.assertEquals(TextOrientation.DOWNWARD, table.getRows().get(1).getCells().get(1).getCellFormat().getOrientation());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.BuildTable.docx");
      • 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 a document builder's cursor to different nodes in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a valid bookmark, an entity that consists of nodes enclosed by a bookmark start node,
        // and a bookmark end node. 
        builder.startBookmark("MyBookmark");
        builder.write("Bookmark contents.");
        builder.endBookmark("MyBookmark");
        
        NodeCollection firstParagraphNodes = doc.getFirstSection().getBody().getFirstParagraph().getChildNodes();
        
        Assert.assertEquals(NodeType.BOOKMARK_START, firstParagraphNodes.get(0).getNodeType());
        Assert.assertEquals(NodeType.RUN, firstParagraphNodes.get(1).getNodeType());
        Assert.assertEquals("Bookmark contents.", firstParagraphNodes.get(1).getText().trim());
        Assert.assertEquals(NodeType.BOOKMARK_END, firstParagraphNodes.get(2).getNodeType());
        
        // The document builder's cursor is always ahead of the node that we last added with it.
        // If the builder's cursor is at the end of the document, its current node will be null.
        // The previous node is the bookmark end node that we last added.
        // Adding new nodes with the builder will append them to the last node.
        Assert.assertNull(builder.getCurrentNode());
        
        // If we wish to edit a different part of the document with the builder,
        // we will need to bring its cursor to the node we wish to edit.
        builder.moveToBookmark("MyBookmark");
        
        // Moving it to a bookmark will move it to the first node within the bookmark start and end nodes, the enclosed run.
        Assert.assertEquals(firstParagraphNodes.get(1), builder.getCurrentNode());
        
        // We can also move the cursor to an individual node like this.
        builder.moveTo(doc.getFirstSection().getBody().getFirstParagraph().getChildNodes(NodeType.ANY, false).get(0));
        
        Assert.assertEquals(NodeType.BOOKMARK_START, builder.getCurrentNode().getNodeType());
        Assert.assertEquals(doc.getFirstSection().getBody().getFirstParagraph(), builder.getCurrentParagraph());
        Assert.assertTrue(builder.isAtStartOfParagraph());
        
        // We can use specific methods to move to the start/end of a document.
        builder.moveToDocumentEnd();
        
        Assert.assertTrue(builder.isAtEndOfParagraph());
        
        builder.moveToDocumentStart();
        
        Assert.assertTrue(builder.isAtStartOfParagraph());
        See Also:
        CurrentParagraph
      • getCurrentParagraph

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

        Example:

        Shows how to move a document builder's cursor to different nodes in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a valid bookmark, an entity that consists of nodes enclosed by a bookmark start node,
        // and a bookmark end node. 
        builder.startBookmark("MyBookmark");
        builder.write("Bookmark contents.");
        builder.endBookmark("MyBookmark");
        
        NodeCollection firstParagraphNodes = doc.getFirstSection().getBody().getFirstParagraph().getChildNodes();
        
        Assert.assertEquals(NodeType.BOOKMARK_START, firstParagraphNodes.get(0).getNodeType());
        Assert.assertEquals(NodeType.RUN, firstParagraphNodes.get(1).getNodeType());
        Assert.assertEquals("Bookmark contents.", firstParagraphNodes.get(1).getText().trim());
        Assert.assertEquals(NodeType.BOOKMARK_END, firstParagraphNodes.get(2).getNodeType());
        
        // The document builder's cursor is always ahead of the node that we last added with it.
        // If the builder's cursor is at the end of the document, its current node will be null.
        // The previous node is the bookmark end node that we last added.
        // Adding new nodes with the builder will append them to the last node.
        Assert.assertNull(builder.getCurrentNode());
        
        // If we wish to edit a different part of the document with the builder,
        // we will need to bring its cursor to the node we wish to edit.
        builder.moveToBookmark("MyBookmark");
        
        // Moving it to a bookmark will move it to the first node within the bookmark start and end nodes, the enclosed run.
        Assert.assertEquals(firstParagraphNodes.get(1), builder.getCurrentNode());
        
        // We can also move the cursor to an individual node like this.
        builder.moveTo(doc.getFirstSection().getBody().getFirstParagraph().getChildNodes(NodeType.ANY, false).get(0));
        
        Assert.assertEquals(NodeType.BOOKMARK_START, builder.getCurrentNode().getNodeType());
        Assert.assertEquals(doc.getFirstSection().getBody().getFirstParagraph(), builder.getCurrentParagraph());
        Assert.assertTrue(builder.isAtStartOfParagraph());
        
        // We can use specific methods to move to the start/end of a document.
        builder.moveToDocumentEnd();
        
        Assert.assertTrue(builder.isAtEndOfParagraph());
        
        builder.moveToDocumentStart();
        
        Assert.assertTrue(builder.isAtStartOfParagraph());
      • 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.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Shape shape = builder.insertImage(getImageDir() + "Logo.jpg");
        shape.setWrapType(WrapType.NONE);
        
        // Configure the shape's "RelativeHorizontalPosition" property to treat the value of the "Left" property
        // as the shape's horizontal distance, in points, from the left side of the page. 
        shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        
        // Set the shape's horizontal distance from the left side of the page to 100.
        shape.setLeft(100.0);
        
        // Use the "RelativeVerticalPosition" property in a similar way to position the shape 80pt below the top of the page.
        shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        shape.setTop(80.0);
        
        // Set the shape's height, which will automatically scale the width to preserve dimensions.
        shape.setHeight(125.0);
        
        Assert.assertEquals(125.0d, shape.getWidth());
        
        // The "Bottom" and "Right" properties contain the bottom and right edges of the image.
        Assert.assertEquals(shape.getTop() + shape.getHeight(), shape.getBottom());
        Assert.assertEquals(shape.getLeft() + shape.getWidth(), shape.getRight());
        
        doc.save(getArtifactsDir() + "Image.CreateFloatingPositionSize.docx");
      • getCurrentStory

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

        Example:

        Shows how to work with a document builder's current story.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // A Story is a type of node that has child Paragraph nodes, such as a Body.
        Assert.assertEquals(builder.getCurrentStory(), doc.getFirstSection().getBody());
        Assert.assertEquals(builder.getCurrentStory(), builder.getCurrentParagraph().getParentNode());
        Assert.assertEquals(StoryType.MAIN_TEXT, builder.getCurrentStory().getStoryType());
        
        builder.getCurrentStory().appendParagraph("Text added to current Story.");
        
        // A Story can also contain tables.
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Row 1, cell 1");
        builder.insertCell();
        builder.write("Row 1, cell 2");
        builder.endTable();
        
        Assert.assertTrue(builder.getCurrentStory().getTables().contains(table));
      • 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 apply and revert page setup settings to sections in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Modify the page setup properties for the builder's current section and add text.
        builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
        builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
        builder.writeln("This is the first section, which landscape oriented with vertically centered text.");
        
        // If we start a new section using a document builder,
        // it will inherit the builder's current page setup properties.
        builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
        
        Assert.assertEquals(Orientation.LANDSCAPE, doc.getSections().get(1).getPageSetup().getOrientation());
        Assert.assertEquals(PageVerticalAlignment.CENTER, doc.getSections().get(1).getPageSetup().getVerticalAlignment());
        
        // We can revert its page setup properties to their default values using the "ClearFormatting" method.
        builder.getPageSetup().clearFormatting();
        
        Assert.assertEquals(Orientation.PORTRAIT, doc.getSections().get(1).getPageSetup().getOrientation());
        Assert.assertEquals(PageVerticalAlignment.TOP, doc.getSections().get(1).getPageSetup().getVerticalAlignment());
        
        builder.writeln("This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
        
        doc.save(getArtifactsDir() + "PageSetup.ClearFormatting.docx");
      • 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:

        Shows how to insert a string surrounded by a border into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().getBorder().setColor(Color.GREEN);
        builder.getFont().getBorder().setLineWidth(2.5);
        builder.getFont().getBorder().setLineStyle(LineStyle.DASH_DOT_STROKER);
        
        builder.write("Text surrounded by green border.");
        
        doc.save(getArtifactsDir() + "Border.FontBorder.docx");

        Example:

        Shows how to create a formatted table using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        table.setLeftIndent(20.0);
        
        // Set some formatting options for text and table appearance.
        builder.getRowFormat().setHeight(40.0);
        builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);
        builder.getCellFormat().getShading().setBackgroundPatternColor(new Color((198), (217), (241)));
        
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        builder.getFont().setSize(16.0);
        builder.getFont().setName("Arial");
        builder.getFont().setBold(true);
        
        // Configuring the formatting options in a document builder will apply them
        // to the current cell/row its cursor is in,
        // as well as any new cells and rows created using that builder.
        builder.write("Header Row,\n Cell 1");
        builder.insertCell();
        builder.write("Header Row,\n Cell 2");
        builder.insertCell();
        builder.write("Header Row,\n Cell 3");
        builder.endRow();
        
        // Reconfigure the builder's formatting objects for new rows and cells that we are about to make.
        // The builder will not apply these to the first row already created so that it will stand out as a header row.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.getRowFormat().setHeight(30.0);
        builder.getRowFormat().setHeightRule(HeightRule.AUTO);
        builder.insertCell();
        builder.getFont().setSize(12.0);
        builder.getFont().setBold(false);
        
        builder.write("Row 1, Cell 1.");
        builder.insertCell();
        builder.write("Row 1, Cell 2.");
        builder.insertCell();
        builder.write("Row 1, Cell 3.");
        builder.endRow();
        builder.insertCell();
        builder.write("Row 2, Cell 1.");
        builder.insertCell();
        builder.write("Row 2, Cell 2.");
        builder.insertCell();
        builder.write("Row 2, Cell 3.");
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.CreateFormattedTable.docx");
      • isAtEndOfParagraph

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

        Example:

        Shows how to move a document builder's cursor to different nodes in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a valid bookmark, an entity that consists of nodes enclosed by a bookmark start node,
        // and a bookmark end node. 
        builder.startBookmark("MyBookmark");
        builder.write("Bookmark contents.");
        builder.endBookmark("MyBookmark");
        
        NodeCollection firstParagraphNodes = doc.getFirstSection().getBody().getFirstParagraph().getChildNodes();
        
        Assert.assertEquals(NodeType.BOOKMARK_START, firstParagraphNodes.get(0).getNodeType());
        Assert.assertEquals(NodeType.RUN, firstParagraphNodes.get(1).getNodeType());
        Assert.assertEquals("Bookmark contents.", firstParagraphNodes.get(1).getText().trim());
        Assert.assertEquals(NodeType.BOOKMARK_END, firstParagraphNodes.get(2).getNodeType());
        
        // The document builder's cursor is always ahead of the node that we last added with it.
        // If the builder's cursor is at the end of the document, its current node will be null.
        // The previous node is the bookmark end node that we last added.
        // Adding new nodes with the builder will append them to the last node.
        Assert.assertNull(builder.getCurrentNode());
        
        // If we wish to edit a different part of the document with the builder,
        // we will need to bring its cursor to the node we wish to edit.
        builder.moveToBookmark("MyBookmark");
        
        // Moving it to a bookmark will move it to the first node within the bookmark start and end nodes, the enclosed run.
        Assert.assertEquals(firstParagraphNodes.get(1), builder.getCurrentNode());
        
        // We can also move the cursor to an individual node like this.
        builder.moveTo(doc.getFirstSection().getBody().getFirstParagraph().getChildNodes(NodeType.ANY, false).get(0));
        
        Assert.assertEquals(NodeType.BOOKMARK_START, builder.getCurrentNode().getNodeType());
        Assert.assertEquals(doc.getFirstSection().getBody().getFirstParagraph(), builder.getCurrentParagraph());
        Assert.assertTrue(builder.isAtStartOfParagraph());
        
        // We can use specific methods to move to the start/end of a document.
        builder.moveToDocumentEnd();
        
        Assert.assertTrue(builder.isAtEndOfParagraph());
        
        builder.moveToDocumentStart();
        
        Assert.assertTrue(builder.isAtStartOfParagraph());
      • isAtStartOfParagraph

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

        Example:

        Shows how to move a document builder's cursor to different nodes in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a valid bookmark, an entity that consists of nodes enclosed by a bookmark start node,
        // and a bookmark end node. 
        builder.startBookmark("MyBookmark");
        builder.write("Bookmark contents.");
        builder.endBookmark("MyBookmark");
        
        NodeCollection firstParagraphNodes = doc.getFirstSection().getBody().getFirstParagraph().getChildNodes();
        
        Assert.assertEquals(NodeType.BOOKMARK_START, firstParagraphNodes.get(0).getNodeType());
        Assert.assertEquals(NodeType.RUN, firstParagraphNodes.get(1).getNodeType());
        Assert.assertEquals("Bookmark contents.", firstParagraphNodes.get(1).getText().trim());
        Assert.assertEquals(NodeType.BOOKMARK_END, firstParagraphNodes.get(2).getNodeType());
        
        // The document builder's cursor is always ahead of the node that we last added with it.
        // If the builder's cursor is at the end of the document, its current node will be null.
        // The previous node is the bookmark end node that we last added.
        // Adding new nodes with the builder will append them to the last node.
        Assert.assertNull(builder.getCurrentNode());
        
        // If we wish to edit a different part of the document with the builder,
        // we will need to bring its cursor to the node we wish to edit.
        builder.moveToBookmark("MyBookmark");
        
        // Moving it to a bookmark will move it to the first node within the bookmark start and end nodes, the enclosed run.
        Assert.assertEquals(firstParagraphNodes.get(1), builder.getCurrentNode());
        
        // We can also move the cursor to an individual node like this.
        builder.moveTo(doc.getFirstSection().getBody().getFirstParagraph().getChildNodes(NodeType.ANY, false).get(0));
        
        Assert.assertEquals(NodeType.BOOKMARK_START, builder.getCurrentNode().getNodeType());
        Assert.assertEquals(doc.getFirstSection().getBody().getFirstParagraph(), builder.getCurrentParagraph());
        Assert.assertTrue(builder.isAtStartOfParagraph());
        
        // We can use specific methods to move to the start/end of a document.
        builder.moveToDocumentEnd();
        
        Assert.assertTrue(builder.isAtEndOfParagraph());
        
        builder.moveToDocumentStart();
        
        Assert.assertTrue(builder.isAtStartOfParagraph());
      • getItalic/setItalic

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

        Example:

        Shows how to fill MERGEFIELDs with data with a document builder instead of a mail merge.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert some MERGEFIELDS, which accept data from columns of the same name in a data source during a mail merge,
        // and then fill them manually.
        builder.insertField(" MERGEFIELD Chairman ");
        builder.insertField(" MERGEFIELD ChiefFinancialOfficer ");
        builder.insertField(" MERGEFIELD ChiefTechnologyOfficer ");
        
        builder.moveToMergeField("Chairman");
        builder.setBold(true);
        builder.writeln("John Doe");
        
        builder.moveToMergeField("ChiefFinancialOfficer");
        builder.setItalic(true);
        builder.writeln("Jane Doe");
        
        builder.moveToMergeField("ChiefTechnologyOfficer");
        builder.setItalic(true);
        builder.writeln("John Bloggs");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.FillMergeFields.docx");
      • getListFormat

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

        Example:

        Shows how to create bulleted and numbered lists.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Aspose.Words main advantages are:");
        
        // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
        // We can create nested lists by increasing the indent level. 
        // We can begin and end a list by using a document builder's "ListFormat" property. 
        // Each paragraph that we add between a list's start and the end will become an item in the list.
        // Below are two types of lists that we can create with a document builder.
        // 1 -  A bulleted list:
        // This list will apply an indent and a bullet symbol ("�") before each paragraph.
        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.insertBreak(BreakType.PARAGRAPH_BREAK);
        builder.writeln("Aspose.Words allows:");
        
        // 2 -  A numbered list:
        // Numbered lists create a logical order for their paragraphs by numbering each item.
        builder.getListFormat().applyNumberDefault();
        
        // This paragraph is the first item. The first item of a numbered list will have a "1." as its list item symbol.
        builder.writeln("Opening documents from different formats:");
        
        Assert.assertEquals(0, builder.getListFormat().getListLevelNumber());
        
        // Call the "ListIndent" method to increase the current list level,
        // which will start a new self-contained list, with a deeper indent, at the current item of the first list level.
        builder.getListFormat().listIndent();
        
        Assert.assertEquals(1, builder.getListFormat().getListLevelNumber());
        
        // These are the first three list items of the second list level, which will maintain a count
        // independent of the count of the first list level. According to the current list format,
        // they will have symbols of "a.", "b.", and "c.".
        builder.writeln("DOC");
        builder.writeln("PDF");
        builder.writeln("HTML");
        
        // Call the "ListOutdent" method to return to the previous list level.
        builder.getListFormat().listOutdent();
        
        Assert.assertEquals(0, builder.getListFormat().getListLevelNumber());
        
        // These two paragraphs will continue the count of the first list level.
        // These items will have symbols of "2.", and "3."
        builder.writeln("Processing documents");
        builder.writeln("Saving documents in different formats:");
        
        // If we increase the list level to a level that we have added items to previously,
        // the nested list will be separate from the previous, and its numbering will start from the beginning. 
        // These list items will have symbols of "a.", "b.", "c.", "d.", and "e".
        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();
        
        doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
      • getPageSetup

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

        Example:

        Shows how to apply and revert page setup settings to sections in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Modify the page setup properties for the builder's current section and add text.
        builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
        builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
        builder.writeln("This is the first section, which landscape oriented with vertically centered text.");
        
        // If we start a new section using a document builder,
        // it will inherit the builder's current page setup properties.
        builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
        
        Assert.assertEquals(Orientation.LANDSCAPE, doc.getSections().get(1).getPageSetup().getOrientation());
        Assert.assertEquals(PageVerticalAlignment.CENTER, doc.getSections().get(1).getPageSetup().getVerticalAlignment());
        
        // We can revert its page setup properties to their default values using the "ClearFormatting" method.
        builder.getPageSetup().clearFormatting();
        
        Assert.assertEquals(Orientation.PORTRAIT, doc.getSections().get(1).getPageSetup().getOrientation());
        Assert.assertEquals(PageVerticalAlignment.TOP, doc.getSections().get(1).getPageSetup().getVerticalAlignment());
        
        builder.writeln("This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
        
        doc.save(getArtifactsDir() + "PageSetup.ClearFormatting.docx");
      • 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();
        builder.insertCell();
        table.setLeftIndent(20.0);
        
        // Set some formatting options for text and table appearance.
        builder.getRowFormat().setHeight(40.0);
        builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);
        builder.getCellFormat().getShading().setBackgroundPatternColor(new Color((198), (217), (241)));
        
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        builder.getFont().setSize(16.0);
        builder.getFont().setName("Arial");
        builder.getFont().setBold(true);
        
        // Configuring the formatting options in a document builder will apply them
        // to the current cell/row its cursor is in,
        // as well as any new cells and rows created using that builder.
        builder.write("Header Row,\n Cell 1");
        builder.insertCell();
        builder.write("Header Row,\n Cell 2");
        builder.insertCell();
        builder.write("Header Row,\n Cell 3");
        builder.endRow();
        
        // Reconfigure the builder's formatting objects for new rows and cells that we are about to make.
        // The builder will not apply these to the first row already created so that it will stand out as a header row.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.getRowFormat().setHeight(30.0);
        builder.getRowFormat().setHeightRule(HeightRule.AUTO);
        builder.insertCell();
        builder.getFont().setSize(12.0);
        builder.getFont().setBold(false);
        
        builder.write("Row 1, Cell 1.");
        builder.insertCell();
        builder.write("Row 1, Cell 2.");
        builder.insertCell();
        builder.write("Row 1, Cell 3.");
        builder.endRow();
        builder.insertCell();
        builder.write("Row 2, Cell 1.");
        builder.insertCell();
        builder.write("Row 2, Cell 2.");
        builder.insertCell();
        builder.write("Row 2, Cell 3.");
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.CreateFormattedTable.docx");
      • getRowFormat

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

        Example:

        Shows how to format rows with a document builder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Row 1, cell 1.");
        
        // Start a second row, and then configure its height. The builder will apply these settings to
        // its current row, as well as any new rows it creates afterwards.
        builder.endRow();
        
        RowFormat rowFormat = builder.getRowFormat();
        rowFormat.setHeight(100.0);
        rowFormat.setHeightRule(HeightRule.EXACTLY);
        
        builder.insertCell();
        builder.write("Row 2, cell 1.");
        builder.endTable();
        
        // The first row was unaffected by the padding reconfiguration and still holds the default values.
        Assert.assertEquals(0.0d, table.getRows().get(0).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.AUTO, table.getRows().get(0).getRowFormat().getHeightRule());
        
        Assert.assertEquals(100.0d, table.getRows().get(1).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.EXACTLY, table.getRows().get(1).getRowFormat().getHeightRule());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.SetRowFormatting.docx");

        Example:

        Shows how to build a table with custom borders.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        
        // Setting table formatting options for a document builder
        // will apply them to every row and cell that we add with it.
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        
        builder.getCellFormat().clearFormatting();
        builder.getCellFormat().setWidth(150.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.getCellFormat().setWrapText(false);
        builder.getCellFormat().setFitText(true);
        
        builder.getRowFormat().clearFormatting();
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getRowFormat().setHeight(50.0);
        builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D);
        builder.getRowFormat().getBorders().setColor(Color.ORANGE);
        
        builder.insertCell();
        builder.write("Row 1, Col 1");
        
        builder.insertCell();
        builder.write("Row 1, Col 2");
        builder.endRow();
        
        // Changing the formatting will apply it to the current cell,
        // and any new cells that we create with the builder afterward.
        // This will not affect the cells that we have added previously.
        builder.getCellFormat().getShading().clearFormatting();
        
        builder.insertCell();
        builder.write("Row 2, Col 1");
        
        builder.insertCell();
        builder.write("Row 2, Col 2");
        
        builder.endRow();
        
        // Increase row height to fit the vertical text.
        builder.insertCell();
        builder.getRowFormat().setHeight(150.0);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 3, Col 1");
        
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 3, Col 2");
        
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");

        Example:

        Shows how to build a formatted 2x2 table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("Row 1, cell 1.");
        builder.insertCell();
        builder.write("Row 1, cell 2.");
        builder.endRow();
        
        // While building the table, the document builder will apply its current RowFormat/CellFormat property values
        // to the current row/cell that its cursor is in and any new rows/cells as it creates them.
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(0).getCellFormat().getVerticalAlignment());
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(1).getCellFormat().getVerticalAlignment());
        
        builder.insertCell();
        builder.getRowFormat().setHeight(100.0);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 2, cell 1.");
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 2, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
        Assert.assertEquals(0.0, table.getRows().get(0).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.AUTO, table.getRows().get(0).getRowFormat().getHeightRule());
        Assert.assertEquals(100.0, table.getRows().get(1).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.EXACTLY, table.getRows().get(1).getRowFormat().getHeightRule());
        Assert.assertEquals(TextOrientation.UPWARD, table.getRows().get(1).getCells().get(0).getCellFormat().getOrientation());
        Assert.assertEquals(TextOrientation.DOWNWARD, table.getRows().get(1).getCells().get(1).getCellFormat().getOrientation());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.BuildTable.docx");
      • 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.

        Example:

        Shows how to format text inserted by a document builder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.setUnderline(Underline.DASH);
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setSize(32.0);
        
        // The builder applies formatting to its current paragraph and any new text added by it afterward.
        builder.writeln("Large, blue, and underlined text.");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertUnderline.docx");
    • 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();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Row 1, cell 1.");
        builder.insertCell();
        builder.write("Row 1, cell 2.");
        builder.endRow();
        builder.insertCell();
        builder.write("Row 2, cell 1.");
        builder.insertCell();
        builder.write("Row 2, cell 2.");
        builder.endTable();
        
        Assert.assertEquals(2, table.getRows().getCount());
        
        // Delete the first row of the first table in the document.
        builder.deleteRow(0, 0);
        
        Assert.assertEquals(1, table.getRows().getCount());
        Assert.assertEquals("Row 2, cell 1.\u0007Row 2, cell 2.", table.getText().trim());
      • 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:

        Shows how to insert a hyperlink which references a local bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startBookmark("Bookmark1");
        builder.write("Bookmarked text. ");
        builder.endBookmark("Bookmark1");
        builder.writeln("Text outside of the bookmark.");
        
        // Insert a HYPERLINK field that links to the bookmark. We can pass field switches
        // to the "InsertHyperlink" method as part of the argument containing the referenced bookmark's name.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        builder.insertHyperlink("Link to Bookmark1", "Bookmark1\" \\o \"Hyperlink Tip", true);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertHyperlinkToLocalBookmark.docx");

        Example:

        Shows how create a bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // A valid bookmark needs to have document body text enclosed by
        // BookmarkStart and BookmarkEnd nodes created with a matching bookmark name.
        builder.startBookmark("MyBookmark");
        builder.writeln("Hello world!");
        builder.endBookmark("MyBookmark");
        
        Assert.assertEquals(1, doc.getRange().getBookmarks().getCount());
        Assert.assertEquals("MyBookmark", doc.getRange().getBookmarks().get(0).getName());
        Assert.assertEquals("Hello world!", doc.getRange().getBookmarks().get(0).getText().trim());
      • endColumnBookmark

        public BookmarkEnd endColumnBookmark(java.lang.String bookmarkName)
        Marks the current position in the document as a column bookmark end. The position must be in a table cell.

        A column bookmark covers one or more columns in a range of rows. To create a valid bookmark you need to call both startColumnBookmark(java.lang.String) and endColumnBookmark(java.lang.String) with the same bookmarkName parameter.

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

        The actual position of the inserted BookmarkEnd node may differ from the current document builder position.

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

        Example:

        Shows how to create a column bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        
        builder.insertCell();
        // Cells 1,2,4,5 will be bookmarked.
        builder.startColumnBookmark("MyBookmark_1");
        // Badly formed bookmarks or bookmarks with duplicate names will be ignored when the document is saved.
        builder.startColumnBookmark("MyBookmark_1");
        builder.startColumnBookmark("BadStartBookmark");
        builder.write("Cell 1");
        
        builder.insertCell();
        builder.write("Cell 2");
        
        builder.insertCell();
        builder.write("Cell 3");
        
        builder.endRow();
        
        builder.insertCell();
        builder.write("Cell 4");
        
        builder.insertCell();
        builder.write("Cell 5");
        builder.endColumnBookmark("MyBookmark_1");
        builder.endColumnBookmark("MyBookmark_1");
        
        builder.insertCell();
        builder.write("Cell 6");
        
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "Bookmarks.CreateColumnBookmark.docx");
      • 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 work with an editable range.
        Document doc = new Document();
        doc.protect(ProtectionType.READ_ONLY, "MyPassword");
        
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world! Since we have set the document's protection level to read-only," +
                " we cannot edit this paragraph without the password.");
        
        // Editable ranges allow us to leave parts of protected documents open for editing.
        EditableRangeStart editableRangeStart = builder.startEditableRange();
        builder.writeln("This paragraph is inside an editable range, and can be edited.");
        EditableRangeEnd editableRangeEnd = builder.endEditableRange();
        
        // A well-formed editable range has a start node, and end node.
        // These nodes have matching IDs and encompass editable nodes.
        EditableRange editableRange = editableRangeStart.getEditableRange();
        
        Assert.assertEquals(editableRangeStart.getId(), editableRange.getId());
        Assert.assertEquals(editableRangeEnd.getId(), editableRange.getId());
        
        // Different parts of the editable range link to each other.
        Assert.assertEquals(editableRangeStart.getId(), editableRange.getEditableRangeStart().getId());
        Assert.assertEquals(editableRangeStart.getId(), editableRangeEnd.getEditableRangeStart().getId());
        Assert.assertEquals(editableRange.getId(), editableRangeStart.getEditableRange().getId());
        Assert.assertEquals(editableRangeEnd.getId(), editableRange.getEditableRangeEnd().getId());
        
        // We can access the node types of each part like this. The editable range itself is not a node,
        // but an entity which consists of a start, an end, and their enclosed contents.
        Assert.assertEquals(NodeType.EDITABLE_RANGE_START, editableRangeStart.getNodeType());
        Assert.assertEquals(NodeType.EDITABLE_RANGE_END, editableRangeEnd.getNodeType());
        
        builder.writeln("This paragraph is outside the editable range, and cannot be edited.");
        
        doc.save(getArtifactsDir() + "EditableRange.CreateAndRemove.docx");
        
        // Remove an editable range. All the nodes that were inside the range will remain intact.
        editableRange.remove();
      • 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 create nested editable ranges.
        Document doc = new Document();
        doc.protect(ProtectionType.READ_ONLY, "MyPassword");
        
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world! Since we have set the document's protection level to read-only, " +
                "we cannot edit this paragraph without the password.");
        
        // Create two nested editable ranges.
        EditableRangeStart outerEditableRangeStart = builder.startEditableRange();
        builder.writeln("This paragraph inside the outer editable range and can be edited.");
        
        EditableRangeStart innerEditableRangeStart = builder.startEditableRange();
        builder.writeln("This paragraph inside both the outer and inner editable ranges and can be edited.");
        
        // Currently, the document builder's node insertion cursor is in more than one ongoing editable range.
        // When we want to end an editable range in this situation,
        // we need to specify which of the ranges we wish to end by passing its EditableRangeStart node.
        builder.endEditableRange(innerEditableRangeStart);
        
        builder.writeln("This paragraph inside the outer editable range and can be edited.");
        
        builder.endEditableRange(outerEditableRangeStart);
        
        builder.writeln("This paragraph is outside any editable ranges, and cannot be edited.");
        
        // If a region of text has two overlapping editable ranges with specified groups,
        // the combined group of users excluded by both groups are prevented from editing it.
        outerEditableRangeStart.getEditableRange().setEditorGroup(EditorType.EVERYONE);
        innerEditableRangeStart.getEditableRange().setEditorGroup(EditorType.CONTRIBUTORS);
        
        doc.save(getArtifactsDir() + "EditableRange.Nested.docx");
      • 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 2x2 table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("Row 1, cell 1.");
        builder.insertCell();
        builder.write("Row 1, cell 2.");
        builder.endRow();
        
        // While building the table, the document builder will apply its current RowFormat/CellFormat property values
        // to the current row/cell that its cursor is in and any new rows/cells as it creates them.
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(0).getCellFormat().getVerticalAlignment());
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(1).getCellFormat().getVerticalAlignment());
        
        builder.insertCell();
        builder.getRowFormat().setHeight(100.0);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 2, cell 1.");
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 2, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
        Assert.assertEquals(0.0, table.getRows().get(0).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.AUTO, table.getRows().get(0).getRowFormat().getHeightRule());
        Assert.assertEquals(100.0, table.getRows().get(1).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.EXACTLY, table.getRows().get(1).getRowFormat().getHeightRule());
        Assert.assertEquals(TextOrientation.UPWARD, table.getRows().get(1).getCells().get(0).getCellFormat().getOrientation());
        Assert.assertEquals(TextOrientation.DOWNWARD, table.getRows().get(1).getCells().get(1).getCellFormat().getOrientation());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.BuildTable.docx");

        Example:

        Shows how to build a table with custom borders.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        
        // Setting table formatting options for a document builder
        // will apply them to every row and cell that we add with it.
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        
        builder.getCellFormat().clearFormatting();
        builder.getCellFormat().setWidth(150.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.getCellFormat().setWrapText(false);
        builder.getCellFormat().setFitText(true);
        
        builder.getRowFormat().clearFormatting();
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getRowFormat().setHeight(50.0);
        builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D);
        builder.getRowFormat().getBorders().setColor(Color.ORANGE);
        
        builder.insertCell();
        builder.write("Row 1, Col 1");
        
        builder.insertCell();
        builder.write("Row 1, Col 2");
        builder.endRow();
        
        // Changing the formatting will apply it to the current cell,
        // and any new cells that we create with the builder afterward.
        // This will not affect the cells that we have added previously.
        builder.getCellFormat().getShading().clearFormatting();
        
        builder.insertCell();
        builder.write("Row 2, Col 1");
        
        builder.insertCell();
        builder.write("Row 2, Col 2");
        
        builder.endRow();
        
        // Increase row height to fit the vertical text.
        builder.insertCell();
        builder.getRowFormat().setHeight(150.0);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 3, Col 1");
        
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 3, Col 2");
        
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");

        Example:

        Shows how to merge table cells vertically.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a cell into the first column of the first row.
        // This cell will be the first in a range of vertically merged cells.
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
        builder.write("Text in merged cells.");
        
        // Insert a cell into the second column of the first row, then end the row.
        // Also, configure the builder to disable vertical merging in created cells.
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
        builder.write("Text in unmerged cell.");
        builder.endRow();
        
        // Insert a cell into the first column of the second row. 
        // Instead of adding text contents, we will merge this cell with the first cell that we added directly above.
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
        
        // Insert another independent cell in the second column of the second row.
        builder.insertCell();
        builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
        builder.write("Text in unmerged cell.");
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "CellFormat.VerticalMerge.docx");
      • 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 2x2 table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("Row 1, cell 1.");
        builder.insertCell();
        builder.write("Row 1, cell 2.");
        builder.endRow();
        
        // While building the table, the document builder will apply its current RowFormat/CellFormat property values
        // to the current row/cell that its cursor is in and any new rows/cells as it creates them.
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(0).getCellFormat().getVerticalAlignment());
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(1).getCellFormat().getVerticalAlignment());
        
        builder.insertCell();
        builder.getRowFormat().setHeight(100.0);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 2, cell 1.");
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 2, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
        Assert.assertEquals(0.0, table.getRows().get(0).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.AUTO, table.getRows().get(0).getRowFormat().getHeightRule());
        Assert.assertEquals(100.0, table.getRows().get(1).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.EXACTLY, table.getRows().get(1).getRowFormat().getHeightRule());
        Assert.assertEquals(TextOrientation.UPWARD, table.getRows().get(1).getCells().get(0).getCellFormat().getOrientation());
        Assert.assertEquals(TextOrientation.DOWNWARD, table.getRows().get(1).getCells().get(1).getCellFormat().getOrientation());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.BuildTable.docx");

        Example:

        Shows how to format cells with a document builder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Row 1, cell 1.");
        
        // Insert a second cell, and then configure cell text padding options.
        // The builder will apply these settings at its current cell, and any new cells creates afterwards.
        builder.insertCell();
        
        CellFormat cellFormat = builder.getCellFormat();
        cellFormat.setWidth(250.0);
        cellFormat.setLeftPadding(30.0);
        cellFormat.setRightPadding(30.0);
        cellFormat.setTopPadding(30.0);
        cellFormat.setBottomPadding(30.0);
        
        builder.write("Row 1, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // The first cell was unaffected by the padding reconfiguration, and still holds the default values.
        Assert.assertEquals(0.0d, table.getFirstRow().getCells().get(0).getCellFormat().getWidth());
        Assert.assertEquals(5.4d, table.getFirstRow().getCells().get(0).getCellFormat().getLeftPadding());
        Assert.assertEquals(5.4d, table.getFirstRow().getCells().get(0).getCellFormat().getRightPadding());
        Assert.assertEquals(0.0d, table.getFirstRow().getCells().get(0).getCellFormat().getTopPadding());
        Assert.assertEquals(0.0d, table.getFirstRow().getCells().get(0).getCellFormat().getBottomPadding());
        
        Assert.assertEquals(250.0d, table.getFirstRow().getCells().get(1).getCellFormat().getWidth());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getLeftPadding());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getRightPadding());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getTopPadding());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getBottomPadding());
        
        // The first cell will still grow in the output document to match the size of its neighboring cell.
        doc.save(getArtifactsDir() + "DocumentBuilder.SetCellFormatting.docx");

        Example:

        Shows how to build a table with custom borders.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        
        // Setting table formatting options for a document builder
        // will apply them to every row and cell that we add with it.
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        
        builder.getCellFormat().clearFormatting();
        builder.getCellFormat().setWidth(150.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.getCellFormat().setWrapText(false);
        builder.getCellFormat().setFitText(true);
        
        builder.getRowFormat().clearFormatting();
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getRowFormat().setHeight(50.0);
        builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D);
        builder.getRowFormat().getBorders().setColor(Color.ORANGE);
        
        builder.insertCell();
        builder.write("Row 1, Col 1");
        
        builder.insertCell();
        builder.write("Row 1, Col 2");
        builder.endRow();
        
        // Changing the formatting will apply it to the current cell,
        // and any new cells that we create with the builder afterward.
        // This will not affect the cells that we have added previously.
        builder.getCellFormat().getShading().clearFormatting();
        
        builder.insertCell();
        builder.write("Row 2, Col 1");
        
        builder.insertCell();
        builder.write("Row 2, Col 2");
        
        builder.endRow();
        
        // Increase row height to fit the vertical text.
        builder.insertCell();
        builder.getRowFormat().setHeight(150.0);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 3, Col 1");
        
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 3, Col 2");
        
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");
      • 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:

        Shows how to insert a Table of contents (TOC) into a document using heading styles as entries.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a table of contents for the first page of the document.
        // Configure the table to pick up paragraphs with headings of levels 1 to 3.
        // Also, set its entries to be hyperlinks that will take us
        // to the location of the heading when left-clicked in Microsoft Word.
        builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // Populate the table of contents by adding paragraphs with heading styles.
        // Each such heading with a level between 1 and 3 will create an entry in the table.
        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_4);
        builder.writeln("Heading 3.1.3.1");
        builder.writeln("Heading 3.1.3.2");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        builder.writeln("Heading 3.2");
        builder.writeln("Heading 3.3");
        
        // A table of contents is a field of a type that needs to be updated to show an up-to-date result.
        doc.updateFields();
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertToc.docx");

        Example:

        Shows how to apply and revert page setup settings to sections in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Modify the page setup properties for the builder's current section and add text.
        builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
        builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
        builder.writeln("This is the first section, which landscape oriented with vertically centered text.");
        
        // If we start a new section using a document builder,
        // it will inherit the builder's current page setup properties.
        builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
        
        Assert.assertEquals(Orientation.LANDSCAPE, doc.getSections().get(1).getPageSetup().getOrientation());
        Assert.assertEquals(PageVerticalAlignment.CENTER, doc.getSections().get(1).getPageSetup().getVerticalAlignment());
        
        // We can revert its page setup properties to their default values using the "ClearFormatting" method.
        builder.getPageSetup().clearFormatting();
        
        Assert.assertEquals(Orientation.PORTRAIT, doc.getSections().get(1).getPageSetup().getOrientation());
        Assert.assertEquals(PageVerticalAlignment.TOP, doc.getSections().get(1).getPageSetup().getVerticalAlignment());
        
        builder.writeln("This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
        
        doc.save(getArtifactsDir() + "PageSetup.ClearFormatting.docx");

        Example:

        Shows how to create headers and footers in a document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want different headers and footers for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers, then add three pages to the document to display each header type.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header for the first page");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header for even pages");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header for all other pages");
        
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.HeadersAndFooters.docx");
      • 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 build a table with custom borders.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        
        // Setting table formatting options for a document builder
        // will apply them to every row and cell that we add with it.
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        
        builder.getCellFormat().clearFormatting();
        builder.getCellFormat().setWidth(150.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.getCellFormat().setWrapText(false);
        builder.getCellFormat().setFitText(true);
        
        builder.getRowFormat().clearFormatting();
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getRowFormat().setHeight(50.0);
        builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D);
        builder.getRowFormat().getBorders().setColor(Color.ORANGE);
        
        builder.insertCell();
        builder.write("Row 1, Col 1");
        
        builder.insertCell();
        builder.write("Row 1, Col 2");
        builder.endRow();
        
        // Changing the formatting will apply it to the current cell,
        // and any new cells that we create with the builder afterward.
        // This will not affect the cells that we have added previously.
        builder.getCellFormat().getShading().clearFormatting();
        
        builder.insertCell();
        builder.write("Row 2, Col 1");
        
        builder.insertCell();
        builder.write("Row 2, Col 2");
        
        builder.endRow();
        
        // Increase row height to fit the vertical text.
        builder.insertCell();
        builder.getRowFormat().setHeight(150.0);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 3, Col 1");
        
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 3, Col 2");
        
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");

        Example:

        Shows how to use a document builder to create a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Start the table, then populate the first row with two cells.
        builder.startTable();
        builder.insertCell();
        builder.write("Row 1, Cell 1.");
        builder.insertCell();
        builder.write("Row 1, Cell 2.");
        
        // Call the builder's "EndRow" method to start a new row.
        builder.endRow();
        builder.insertCell();
        builder.write("Row 2, Cell 1.");
        builder.insertCell();
        builder.write("Row 2, Cell 2.");
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.CreateTable.docx");
      • 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 pie chart into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Chart chart = builder.insertChart(ChartType.PIE, ConvertUtil.pixelToPoint(300.0),
                ConvertUtil.pixelToPoint(300.0)).getChart();
        chart.getSeries().clear();
        chart.getSeries().add("My fruit",
                new String[]{"Apples", "Bananas", "Cherries"},
                new double[]{1.3, 2.2, 1.5});
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertPieChart.docx");
      • 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 specify position and wrapping while inserting a chart.
        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(getArtifactsDir() + "DocumentBuilder.InsertedChartRelativePosition.docx");
      • 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 into the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert checkboxes of varying sizes and default checked statuses.
        builder.write("Unchecked check box of a default size: ");
        builder.insertCheckBox("", false, false, 0);
        builder.insertParagraph();
        
        builder.write("Large checked check box: ");
        builder.insertCheckBox("CheckBox_Default", true, true, 50);
        builder.insertParagraph();
        
        // Form fields have a name length limit of 20 characters.
        builder.write("Very large checked check box: ");
        builder.insertCheckBox("CheckBox_OnlyCheckedValue", true, 100);
        
        Assert.assertEquals("CheckBox_OnlyChecked", doc.getRange().getFormFields().get(2).getName());
        
        // We can interact with these check boxes in Microsoft Word by double clicking them.
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertCheckBox.docx");
      • 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 checkboxes into the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert checkboxes of varying sizes and default checked statuses.
        builder.write("Unchecked check box of a default size: ");
        builder.insertCheckBox("", false, false, 0);
        builder.insertParagraph();
        
        builder.write("Large checked check box: ");
        builder.insertCheckBox("CheckBox_Default", true, true, 50);
        builder.insertParagraph();
        
        // Form fields have a name length limit of 20 characters.
        builder.write("Very large checked check box: ");
        builder.insertCheckBox("CheckBox_OnlyCheckedValue", true, 100);
        
        Assert.assertEquals("CheckBox_OnlyChecked", doc.getRange().getFormFields().get(2).getName());
        
        // We can interact with these check boxes in Microsoft Word by double clicking them.
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertCheckBox.docx");
      • 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:

        Shows how to create form fields.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Form fields are objects in the document that the user can interact with by being prompted to enter values.
        // We can create them using a document builder, and below are two ways of doing so.
        // 1 -  Basic text input:
        builder.insertTextInput("My text input", TextFormFieldType.REGULAR,
                "", "Enter your name here", 30);
        
        // 2 -  Combo box with prompt text, and a range of possible values:
        String[] items =
                {
                        "-- Select your favorite footwear --", "Sneakers", "Oxfords", "Flip-flops", "Other"
                };
        
        builder.insertParagraph();
        builder.insertComboBox("My combo box", items, 0);
        
        builder.getDocument().save(getArtifactsDir() + "DocumentBuilder.CreateForm.docx");

        Example:

        Shows how to insert a combo box form field into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a form that prompts the user to pick one of the items from the menu.
        builder.write("Pick a fruit: ");
        String[] items = {"Apple", "Banana", "Cherry"};
        builder.insertComboBox("DropDown", items, 0);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertComboBox.docx");
      • insertDocument

        public Node insertDocument(Document srcDoc, int importFormatMode)
        Inserts a document at the cursor position. 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 node of the inserted content.

        Example:

        Shows how to insert a document into another document.
        Document doc = new Document(getMyDir() + "Document.docx");
        
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.moveToDocumentEnd();
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        Document docToInsert = new Document(getMyDir() + "Formatted elements.docx");
        
        builder.insertDocument(docToInsert, ImportFormatMode.KEEP_SOURCE_FORMATTING);
        builder.getDocument().save(getArtifactsDir() + "DocumentBuilder.InsertDocument.docx");
      • insertDocument

        public Node insertDocument(Document srcDoc, int importFormatMode, ImportFormatOptions importFormatOptions)
        Inserts a document at the cursor position. 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.
        importFormatOptions - Allows to specify options that affect formatting of a result document.
        Returns:
        First node of the inserted content.

        Example:

        Shows how to resolve duplicate styles while inserting documents.
        Document dstDoc = new Document();
        DocumentBuilder builder = new DocumentBuilder(dstDoc);
        
        Style myStyle = builder.getDocument().getStyles().add(StyleType.PARAGRAPH, "MyStyle");
        myStyle.getFont().setSize(14.0);
        myStyle.getFont().setName("Courier New");
        myStyle.getFont().setColor(Color.BLUE);
        
        builder.getParagraphFormat().setStyleName(myStyle.getName());
        builder.writeln("Hello world!");
        
        // Clone the document and edit the clone's "MyStyle" style, so it is a different color than that of the original.
        // If we insert the clone into the original document, the two styles with the same name will cause a clash.
        Document srcDoc = dstDoc.deepClone();
        srcDoc.getStyles().get("MyStyle").getFont().setColor(Color.RED);
        
        // When we enable SmartStyleBehavior and use the KeepSourceFormatting import format mode,
        // Aspose.Words will resolve style clashes by converting source document styles.
        // with the same names as destination styles into direct paragraph attributes.
        ImportFormatOptions options = new ImportFormatOptions();
        options.setSmartStyleBehavior(true);
        
        builder.insertDocument(srcDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING, options);
        
        dstDoc.save(getArtifactsDir() + "DocumentBuilder.SmartStyleBehavior.docx");
      • 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);
        
        // Insert two fields while passing a flag which determines whether to update them as the builder inserts them.
        // In some cases, updating fields could be computationally expensive, and it may be a good idea to defer the update.
        doc.getBuiltInDocumentProperties().setAuthor("John Doe");
        builder.write("This document was written by ");
        builder.insertField(FieldType.FIELD_AUTHOR, updateInsertedFieldsImmediately);
        
        builder.insertParagraph();
        builder.write("\nThis is page ");
        builder.insertField(FieldType.FIELD_PAGE, updateInsertedFieldsImmediately);
        
        Assert.assertEquals(" AUTHOR ", doc.getRange().getFields().get(0).getFieldCode());
        Assert.assertEquals(" PAGE ", doc.getRange().getFields().get(1).getFieldCode());
        
        if (updateInsertedFieldsImmediately) {
            Assert.assertEquals("John Doe", doc.getRange().getFields().get(0).getResult());
            Assert.assertEquals("1", doc.getRange().getFields().get(1).getResult());
        } else {
            Assert.assertEquals("", doc.getRange().getFields().get(0).getResult());
            Assert.assertEquals("", doc.getRange().getFields().get(1).getResult());
        
            // We will need to update these fields using the update methods manually.
            doc.getRange().getFields().get(0).update();
        
            Assert.assertEquals("John Doe", doc.getRange().getFields().get(0).getResult());
        
            doc.updateFields();
        
            Assert.assertEquals("1", doc.getRange().getFields().get(1).getResult());
        }
      • 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:

        Shows how to insert fields, and move the document builder's cursor to them.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.insertField("MERGEFIELD MyMergeField1 \\* MERGEFORMAT");
        builder.insertField("MERGEFIELD MyMergeField2 \\* MERGEFORMAT");
        
        // Move the cursor to the first MERGEFIELD.
        builder.moveToMergeField("MyMergeField1", true, false);
        
        // Note that the cursor is placed immediately after the first MERGEFIELD, and before the second.
        Assert.assertEquals(doc.getRange().getFields().get(1).getStart(), builder.getCurrentNode());
        Assert.assertEquals(doc.getRange().getFields().get(0).getEnd(), builder.getCurrentNode().getPreviousSibling());
        
        // If we wish to edit the field's field code or contents using the builder,
        // its cursor would need to be inside a field.
        // To place it inside a field, we would need to call the document builder's MoveTo method
        // and pass the field's start or separator node as an argument.
        builder.write(" Text between our merge fields. ");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.MergeFields.docx");

        Example:

        Shows how to insert a field into a document using a field code.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Field dateField = builder.insertField("DATE \\* MERGEFORMAT");
        
        Assert.assertEquals(FieldType.FIELD_DATE, dateField.getType());
        Assert.assertEquals("DATE \\* MERGEFORMAT", dateField.getFieldCode());
      • 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 set up page numbering in a section.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Section 1, page 1.");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Section 1, page 2.");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Section 1, page 3.");
        builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
        builder.writeln("Section 2, page 1.");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Section 2, page 2.");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Section 2, page 3.");
        
        // Move the document builder to the first section's primary header,
        // which every page in that section will display.
        builder.moveToSection(0);
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        
        // Insert a PAGE field, which will display the number of the current page.
        builder.write("Page ");
        builder.insertField("PAGE", "");
        
        // Configure the section to have the page count that PAGE fields display start from 5.
        // Also, configure all PAGE fields to display their page numbers using uppercase Roman numerals.
        PageSetup pageSetup = doc.getSections().get(0).getPageSetup();
        pageSetup.setRestartPageNumbering(true);
        pageSetup.setPageStartingNumber(5);
        pageSetup.setPageNumberStyle(NumberStyle.UPPERCASE_ROMAN);
        
        // Create another primary header for the second section, with another PAGE field.
        builder.moveToSection(1);
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        builder.write(" - ");
        builder.insertField("PAGE", "");
        builder.write(" - ");
        
        // Configure the section to have the page count that PAGE fields display start from 10.
        // Also, configure all PAGE fields to display their page numbers using Arabic numbers.
        pageSetup = doc.getSections().get(1).getPageSetup();
        pageSetup.setPageStartingNumber(10);
        pageSetup.setRestartPageNumbering(true);
        pageSetup.setPageNumberStyle(NumberStyle.ARABIC);
        
        doc.save(getArtifactsDir() + "PageSetup.PageNumbering.docx");
      • 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 reference text with a footnote and an endnote.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert some text and mark it with a footnote with the IsAuto property set to "true" by default,
        // so the marker seen in the body text will be auto-numbered at "1",
        // and the footnote will appear at the bottom of the page.
        builder.write("This text will be referenced by a footnote.");
        builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote comment regarding referenced text.");
        
        // Insert more text and mark it with an endnote with a custom reference mark,
        // which will be used in place of the number "2" and set "IsAuto" to false.
        builder.write("This text will be referenced by an endnote.");
        builder.insertFootnote(FootnoteType.ENDNOTE, "Endnote comment regarding referenced text.", "CustomMark");
        
        // Footnotes always appear at the bottom of their referenced text,
        // so this page break will not affect the footnote.
        // On the other hand, endnotes are always at the end of the document
        // so that this page break will push the endnote down to the next page.
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertFootnote.docx");
      • 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 reference text with a footnote and an endnote.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert some text and mark it with a footnote with the IsAuto property set to "true" by default,
        // so the marker seen in the body text will be auto-numbered at "1",
        // and the footnote will appear at the bottom of the page.
        builder.write("This text will be referenced by a footnote.");
        builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote comment regarding referenced text.");
        
        // Insert more text and mark it with an endnote with a custom reference mark,
        // which will be used in place of the number "2" and set "IsAuto" to false.
        builder.write("This text will be referenced by an endnote.");
        builder.insertFootnote(FootnoteType.ENDNOTE, "Endnote comment regarding referenced text.", "CustomMark");
        
        // Footnotes always appear at the bottom of their referenced text,
        // so this page break will not affect the footnote.
        // On the other hand, endnotes are always at the end of the document
        // so that this page break will push the endnote down to the next page.
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertFootnote.docx");
      • insertHorizontalRule

        public Shape insertHorizontalRule()
                                  throws java.lang.Exception
        Inserts a horizontal rule shape into the document.
        Returns:
        The shape that is a horizontal rule.

        Example:

        Shows how to insert a horizontal rule shape, and customize its formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        Shape shape = builder.insertHorizontalRule();
        
        HorizontalRuleFormat horizontalRuleFormat = shape.getHorizontalRuleFormat();
        horizontalRuleFormat.setAlignment(HorizontalRuleAlignment.CENTER);
        horizontalRuleFormat.setWidthPercent(70.0);
        horizontalRuleFormat.setHeight(3.0);
        horizontalRuleFormat.setColor(Color.BLUE);
        horizontalRuleFormat.setNoShade(true);
        
        Assert.assertTrue(shape.isHorizontalRule());
        Assert.assertTrue(shape.getHorizontalRuleFormat().getNoShade());
      • insertHtml

        public void insertHtml(java.lang.String html)
                       throws java.lang.Exception
        Inserts an HTML string into the document. You can use this method to insert an HTML fragment or whole HTML document.
        Parameters:
        html - An HTML string to insert into the document.

        Example:

        Shows how to execute a mail merge with a custom callback that handles merge data in the form of HTML documents.
        public void insertHtml() throws Exception {
            Document doc = new Document(getMyDir() + "Field sample - MERGEFIELD.docx");
        
            // Add a handler for the MergeField event
            doc.getMailMerge().setFieldMergingCallback(new HandleMergeFieldInsertHtml());
        
            final String htmlText = "<html>\r\n<h1>Hello world!</h1>\r\n</html>";
        
            // Execute mail merge
            doc.getMailMerge().execute(new String[]{"htmlField1"}, new String[]{htmlText});
        
            // Save resulting document with a new name
            doc.save(getArtifactsDir() + "MailMergeEvent.InsertHtml.docx");
        }
        
        private class HandleMergeFieldInsertHtml implements IFieldMergingCallback {
            /**
             * This is called when merge field is actually merged with data in the document.
             */
            public void fieldMerging(final FieldMergingArgs args) throws Exception {
                // All merge fields that expect HTML data should be marked with some prefix, e.g. 'html'
                if (args.getDocumentFieldName().startsWith("html") && args.getField().getFieldCode().contains("\\b")) {
                    FieldMergeField field = args.getField();
        
                    // Insert the text for this merge field as HTML data, using DocumentBuilder
                    DocumentBuilder builder = new DocumentBuilder(args.getDocument());
                    builder.moveToMergeField(args.getDocumentFieldName());
                    builder.write(field.getTextBefore());
                    builder.insertHtml((String) args.getFieldValue());
        
                    // The HTML text itself should not be inserted
                    // We have already inserted it as an HTML
                    args.setText("");
                }
            }
        
            public void /*IFieldMergingCallback.*/imageFieldMerging(ImageFieldMergingArgs args) {
                // Do nothing
            }
        }

        Example:

        Shows how to use a document builder to insert html content into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        final String HTML = "<p align='right'>Paragraph right</p>" +
                "<b>Implicit paragraph left</b>" +
                "<div align='center'>Div center</div>" +
                "<h1 align='left'>Heading 1 left.</h1>";
        
        builder.insertHtml(HTML);
        
        // Inserting HTML code parses the formatting of each element into equivalent document text formatting.
        ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
        
        Assert.assertEquals("Paragraph right", paragraphs.get(0).getText().trim());
        Assert.assertEquals(ParagraphAlignment.RIGHT, paragraphs.get(0).getParagraphFormat().getAlignment());
        
        Assert.assertEquals("Implicit paragraph left", paragraphs.get(1).getText().trim());
        Assert.assertEquals(ParagraphAlignment.LEFT, paragraphs.get(1).getParagraphFormat().getAlignment());
        Assert.assertTrue(paragraphs.get(1).getRuns().get(0).getFont().getBold());
        
        Assert.assertEquals("Div center", paragraphs.get(2).getText().trim());
        Assert.assertEquals(ParagraphAlignment.CENTER, paragraphs.get(2).getParagraphFormat().getAlignment());
        
        Assert.assertEquals("Heading 1 left.", paragraphs.get(3).getText().trim());
        Assert.assertEquals("Heading 1", paragraphs.get(3).getParagraphFormat().getStyle().getName());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertHtml.docx");
      • insertHtml

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

        You can use this method 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:

        Shows how to apply a document builder's formatting while inserting HTML content.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set a text alignment for the builder, insert an HTML paragraph with a specified alignment, and one without.
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.DISTRIBUTED);
        builder.insertHtml(
                "<p align='right'>Paragraph 1.</p>" +
                        "<p>Paragraph 2.</p>", useBuilderFormatting);
        
        ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
        
        // The first paragraph has an alignment specified. When InsertHtml parses the HTML code,
        // the paragraph alignment value found in the HTML code always supersedes the document builder's value.
        Assert.assertEquals("Paragraph 1.", paragraphs.get(0).getText().trim());
        Assert.assertEquals(ParagraphAlignment.RIGHT, paragraphs.get(0).getParagraphFormat().getAlignment());
        
        // The second paragraph has no alignment specified. It can have its alignment value filled in
        // by the builder's value depending on the flag we passed to the InsertHtml method.
        Assert.assertEquals("Paragraph 2.", paragraphs.get(1).getText().trim());
        Assert.assertEquals(useBuilderFormatting ? ParagraphAlignment.DISTRIBUTED : ParagraphAlignment.LEFT,
                paragraphs.get(1).getParagraphFormat().getAlignment());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertHtmlWithFormatting.docx");
      • insertHtml

        public void insertHtml(java.lang.String html, int options)
                       throws java.lang.Exception
        Inserts an HTML string into the document. Allows to specify additional options. You can use this method to insert an HTML fragment or whole HTML document.
        Parameters:
        html - An HTML string to insert into the document.
        options - A HtmlInsertOptions value. Options that are used when HTML string is inserted.

        Example:

        Shows how to use options while inserting html.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertField(" MERGEFIELD Name ");
        builder.insertParagraph();
        builder.insertField(" MERGEFIELD EMAIL ");
        builder.insertParagraph();
        
        // By default "DocumentBuilder.InsertHtml" inserts a HTML fragment that ends with a block-level HTML element,
        // it normally closes that block-level element and inserts a paragraph break.
        // As a result, a new empty paragraph appears after inserted document.
        // If we specify "HtmlInsertOptions.RemoveLastEmptyParagraph", those extra empty paragraphs will be removed.
        builder.moveToMergeField("NAME");
        builder.insertHtml("<p>John Smith</p>", HtmlInsertOptions.USE_BUILDER_FORMATTING | HtmlInsertOptions.REMOVE_LAST_EMPTY_PARAGRAPH);
        builder.moveToMergeField("EMAIL");
        builder.insertHtml("<p>jsmith@example.com</p>", HtmlInsertOptions.USE_BUILDER_FORMATTING);
        
        doc.save(getArtifactsDir() + "MailMerge.RemoveLastEmptyParagraph.docx");
      • 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 a document builder's formatting stack.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set up font formatting, then write the text that goes before the hyperlink.
        builder.getFont().setName("Arial");
        builder.getFont().setSize(24.0);
        builder.write("To visit Google, hold Ctrl and click ");
        
        // Preserve our current formatting configuration on the stack.
        builder.pushFont();
        
        // Alter the builder's current formatting by applying a new style.
        builder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
        builder.insertHyperlink("here", "http://www.google.com", false);
        
        Assert.assertEquals(Color.BLUE.getRGB(), builder.getFont().getColor().getRGB());
        Assert.assertEquals(Underline.SINGLE, builder.getFont().getUnderline());
        
        // Restore the font formatting that we saved earlier and remove the element from the stack.
        builder.popFont();
        
        Assert.assertEquals(0, builder.getFont().getColor().getRGB());
        Assert.assertEquals(Underline.NONE, builder.getFont().getUnderline());
        
        builder.write(". We hope you enjoyed the example.");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.PushPopFont.docx");

        Example:

        Shows how to insert a hyperlink field.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.write("For more information, please visit the ");
        
        // Insert a hyperlink and emphasize it with custom formatting.
        // The hyperlink will be a clickable piece of text which will take us to the location specified in the URL.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        builder.insertHyperlink("Google website", "https://www.google.com", false);
        builder.getFont().clearFormatting();
        builder.writeln(".");
        
        // Ctrl + left clicking the link in the text in Microsoft Word will take us to the URL via a new web browser window.
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertHyperlink.docx");

        Example:

        Shows how to insert a hyperlink which references a local bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startBookmark("Bookmark1");
        builder.write("Bookmarked text. ");
        builder.endBookmark("Bookmark1");
        builder.writeln("Text outside of the bookmark.");
        
        // Insert a HYPERLINK field that links to the bookmark. We can pass field switches
        // to the "InsertHyperlink" method as part of the argument containing the referenced bookmark's name.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        builder.insertHyperlink("Link to Bookmark1", "Bookmark1\" \\o \"Hyperlink Tip", true);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertHyperlinkToLocalBookmark.docx");
      • 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 insert an image from a byte array into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        byte[] imageByteArray = DocumentHelper.getBytesFromStream(new FileInputStream(getImageDir() + "Logo.jpg"));
        
        // Below are three ways of inserting an image from a byte array.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(imageByteArray);
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(imageByteArray, ConvertUtil.pixelToPoint(250.0), ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(imageByteArray, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN,
                100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromByteArray.docx");
      • 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 insert an image from a byte array into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        byte[] imageByteArray = DocumentHelper.getBytesFromStream(new FileInputStream(getImageDir() + "Logo.jpg"));
        
        // Below are three ways of inserting an image from a byte array.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(imageByteArray);
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(imageByteArray, ConvertUtil.pixelToPoint(250.0), ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(imageByteArray, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN,
                100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromByteArray.docx");
      • 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 insert an image from a byte array into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        byte[] imageByteArray = DocumentHelper.getBytesFromStream(new FileInputStream(getImageDir() + "Logo.jpg"));
        
        // Below are three ways of inserting an image from a byte array.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(imageByteArray);
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(imageByteArray, ConvertUtil.pixelToPoint(250.0), ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(imageByteArray, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN,
                100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromByteArray.docx");
      • 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:

        Shows how to insert an image from an object into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        BufferedImage image = ImageIO.read(new File(getImageDir() + "Logo.jpg"));
        
        // Below are three ways of inserting an image from an Image object instance.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(image);
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(image, ConvertUtil.pixelToPoint(250.0), ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(image, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN,
                100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromImageObject.docx");
      • 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 insert an image from an object into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        BufferedImage image = ImageIO.read(new File(getImageDir() + "Logo.jpg"));
        
        // Below are three ways of inserting an image from an Image object instance.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(image);
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(image, ConvertUtil.pixelToPoint(250.0), ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(image, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN,
                100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromImageObject.docx");
      • 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 insert an image from an object into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        BufferedImage image = ImageIO.read(new File(getImageDir() + "Logo.jpg"));
        
        // Below are three ways of inserting an image from an Image object instance.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(image);
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(image, ConvertUtil.pixelToPoint(250.0), ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(image, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN,
                100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromImageObject.docx");
      • 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 into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create reusable stream.
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        IOUtils.copy(new FileInputStream(getImageDir() + "Logo.jpg"), byteArrayOutputStream);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        
        // Below are three ways of inserting an image from a stream.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(byteArrayInputStream);
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        byteArrayInputStream.reset();
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(byteArrayInputStream, ConvertUtil.pixelToPoint(250.0), ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        byteArrayInputStream.reset();
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(byteArrayInputStream, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN,
                100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromStream.docx");

        Example:

        Shows how to insert a shape with an image from a stream into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        InputStream stream = new FileInputStream(getImageDir() + "Logo.jpg");
        try {
            builder.write("Image from stream: ");
            builder.insertImage(stream);
        } finally {
            stream.close();
        }
        
        doc.save(getArtifactsDir() + "Image.FromStream.docx");
      • 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 insert an image from a stream into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create reusable stream.
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        IOUtils.copy(new FileInputStream(getImageDir() + "Logo.jpg"), byteArrayOutputStream);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        
        // Below are three ways of inserting an image from a stream.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(byteArrayInputStream);
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        byteArrayInputStream.reset();
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(byteArrayInputStream, ConvertUtil.pixelToPoint(250.0), ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        byteArrayInputStream.reset();
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(byteArrayInputStream, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN,
                100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromStream.docx");
      • 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 from a stream into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create reusable stream.
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        IOUtils.copy(new FileInputStream(getImageDir() + "Logo.jpg"), byteArrayOutputStream);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        
        // Below are three ways of inserting an image from a stream.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(byteArrayInputStream);
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        byteArrayInputStream.reset();
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(byteArrayInputStream, ConvertUtil.pixelToPoint(250.0), ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        byteArrayInputStream.reset();
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(byteArrayInputStream, RelativeHorizontalPosition.MARGIN, 100.0, RelativeVerticalPosition.MARGIN,
                100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromStream.docx");
      • 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 an image from the local file system into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are three ways of inserting an image from a local system filename.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(getImageDir() + "Logo.jpg");
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(getImageDir() + "Transparent background logo.png", ConvertUtil.pixelToPoint(250.0),
                ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(getImageDir() + "Windows MetaFile.wmf", RelativeHorizontalPosition.MARGIN, 100.0,
                RelativeVerticalPosition.MARGIN, 100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromFilename.docx");

        Example:

        Shows how to determine which image will be inserted.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertImage(getImageDir() + "Scalable Vector Graphics.svg");
        
        // Aspose.Words insert SVG image to the document as PNG with svgBlip extension
        // that contains the original vector SVG image representation.
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertSvgImage.SvgWithSvgBlip.docx");
        
        // Aspose.Words insert SVG image to the document as PNG, just like Microsoft Word does for old format.
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertSvgImage.Svg.doc");
        
        doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2003);
        
        // Aspose.Words insert SVG image to the document as EMF metafile to keep the image in vector representation.
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertSvgImage.Emf.docx");

        Example:

        Shows how to insert a floating image to the center of a page.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a floating image that will appear behind the overlapping text and align it to the page's center.
        Shape shape = builder.insertImage(getImageDir() + "Logo.jpg");
        shape.setWrapType(WrapType.NONE);
        shape.setBehindText(true);
        shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
        shape.setVerticalAlignment(VerticalAlignment.CENTER);
        
        doc.save(getArtifactsDir() + "Image.CreateFloatingPageCenter.docx");

        Example:

        Shows how to insert a shape with an image into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are two locations where the document builder's "InsertShape" method
        // can source the image that the shape will display.
        // 1 -  Pass a local file system filename of an image file:
        builder.write("Image from local file: ");
        builder.insertImage(getImageDir() + "Logo.jpg");
        builder.writeln();
        
        // 2 -  Pass a URL which points to an image.
        builder.write("Image from a URL: ");
        builder.insertImage(getAsposelogoUri().toURL().openStream());
        builder.writeln();
        
        doc.save(getArtifactsDir() + "Image.FromUrl.docx");

        Example:

        Shows how to insert gif image to the document.
        DocumentBuilder builder = new DocumentBuilder();
        
        // We can insert gif image using path or bytes array.
        // It works only if DocumentBuilder optimized to Word version 2010 or higher.
        // Note, that access to the image bytes causes conversion Gif to Png.
        Shape gifImage = builder.insertImage(getImageDir() + "Graphics Interchange Format.gif");
        
        gifImage = builder.insertImage(DocumentHelper.getBytesFromStream(new FileInputStream(getImageDir() + "Graphics Interchange Format.gif")));
        
        builder.getDocument().save(getArtifactsDir() + "InsertGif.docx");
      • 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 insert an image from the local file system into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are three ways of inserting an image from a local system filename.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(getImageDir() + "Logo.jpg");
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(getImageDir() + "Transparent background logo.png", ConvertUtil.pixelToPoint(250.0),
                ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(getImageDir() + "Windows MetaFile.wmf", RelativeHorizontalPosition.MARGIN, 100.0,
                RelativeVerticalPosition.MARGIN, 100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromFilename.docx");
      • 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 an image from the local file system into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are three ways of inserting an image from a local system filename.
        // 1 -  Inline shape with a default size based on the image's original dimensions:
        builder.insertImage(getImageDir() + "Logo.jpg");
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Inline shape with custom dimensions:
        builder.insertImage(getImageDir() + "Transparent background logo.png", ConvertUtil.pixelToPoint(250.0),
                ConvertUtil.pixelToPoint(144.0));
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 3 -  Floating shape with custom dimensions:
        builder.insertImage(getImageDir() + "Windows MetaFile.wmf", RelativeHorizontalPosition.MARGIN, 100.0,
                RelativeVerticalPosition.MARGIN, 100.0, 200.0, 100.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilderImages.InsertImageFromFilename.docx");

        Example:

        Shows how to insert an image from the local file system into a document while preserving its dimensions.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // The InsertImage method creates a floating shape with the passed image in its image data.
        // We can specify the dimensions of the shape can be passing them to this method.
        Shape imageShape = builder.insertImage(getImageDir() + "Logo.jpg", RelativeHorizontalPosition.MARGIN, 0.0,
                RelativeVerticalPosition.MARGIN, 0.0, -1, -1, WrapType.SQUARE);
        
        // Passing negative values as the intended dimensions will automatically define
        // the shape's dimensions based on the dimensions of its image.
        Assert.assertEquals(300.0d, imageShape.getWidth());
        Assert.assertEquals(300.0d, imageShape.getHeight());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertImageOriginalSize.docx");

        Example:

        Shows how to insert an image.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // There are two ways of using a document builder to source an image and then insert it as a floating shape.
        // 1 -  From a file in the local file system:
        builder.insertImage(getImageDir() + "Transparent background logo.png", RelativeHorizontalPosition.MARGIN, 100.0,
                RelativeVerticalPosition.MARGIN, 0.0, 200.0, 200.0, WrapType.SQUARE);
        
        // 2 -  From a URL:
        builder.insertImage(getAsposelogoUri().toString(), RelativeHorizontalPosition.MARGIN, 100.0,
                RelativeVerticalPosition.MARGIN, 250.0, 200.0, 200.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertFloatingImage.docx");
      • 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.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        String imageFileName = getImageDir() + "Windows MetaFile.wmf";
        
        // Below are two ways of applying an image to a shape so that it can display it.
        // 1 -  Set the shape to contain the image.
        Shape shape = new Shape(builder.getDocument(), ShapeType.IMAGE);
        shape.setWrapType(WrapType.INLINE);
        shape.getImageData().setImage(imageFileName);
        
        builder.insertNode(shape);
        
        doc.save(getArtifactsDir() + "Image.CreateLinkedImage.Embedded.docx");
        
        // Every image that we store in shape will increase the size of our document.
        Assert.assertTrue(new File(getArtifactsDir() + "Image.CreateLinkedImage.Embedded.docx").length() > 70000);
        
        doc.getFirstSection().getBody().getFirstParagraph().removeAllChildren();
        
        // 2 -  Set the shape to link to an image file in the local file system.
        shape = new Shape(builder.getDocument(), ShapeType.IMAGE);
        shape.setWrapType(WrapType.INLINE);
        shape.getImageData().setSourceFullName(imageFileName);
        
        builder.insertNode(shape);
        doc.save(getArtifactsDir() + "Image.CreateLinkedImage.Linked.docx");
        
        // Linking to images will save space and result in a smaller document.
        // However, the document can only display the image correctly while
        // the image file is present at the location that the shape's "SourceFullName" property points to.
        Assert.assertTrue(new File(getArtifactsDir() + "Image.CreateLinkedImage.Linked.docx").length() < 10000);
      • insertOleObjectAsIcon

        public Shape insertOleObjectAsIcon(java.lang.String fileName, boolean isLinked, java.lang.String iconFile, java.lang.String iconCaption)
                                   throws java.lang.Exception
        Inserts an embedded or linked OLE object as icon into the document. Allows to specify icon file and caption. 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.
        iconFile - Full path to the ICO file. If the value is null, Aspose.Words will use a predefined image.
        iconCaption - Icon caption. If the value is null, Aspose.Words will use the file name.
        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);
        
        // OLE objects are links to files in our local file system that can be opened by other installed applications.
        // Double clicking these shapes will launch the application, and then use it to open the linked object.
        // There are three ways of using the InsertOleObject method to insert these shapes and configure their appearance.
        // If 'presentation' is omitted and 'asIcon' is set, this overloaded method selects
        // the icon according to the file extension and uses the filename for the icon caption.
        // 1 -  Image taken from the local file system:
        builder.insertOleObject(getMyDir() + "Spreadsheet.xlsx", false, false, new FileInputStream(getImageDir() + "Logo.jpg"));
        
        // If 'presentation' is omitted and 'asIcon' is set, this overloaded method selects
        // the icon according to 'progId' and uses the filename for the icon caption.
        // 2 -  Icon based on the application that will open the object:
        builder.insertOleObject(getMyDir() + "Spreadsheet.xlsx", "Excel.Sheet", false, true, new FileInputStream(getImageDir() + "Logo.jpg"));
        
        // If 'iconFile' and 'iconCaption' are omitted, this overloaded method selects
        // the icon according to 'progId' and uses the predefined icon caption.
        // 3 -  Image icon that's 32 x 32 pixels or smaller from the local file system, with a custom caption:
        builder.insertOleObjectAsIcon(getMyDir() + "Presentation.pptx", false, getImageDir() + "Logo icon.ico",
                "Double click to view presentation!");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertOleObject.docx");
      • insertOleObjectAsIcon

        public Shape insertOleObjectAsIcon(java.lang.String fileName, java.lang.String progId, boolean isLinked, java.lang.String iconFile, java.lang.String iconCaption)
                                   throws java.lang.Exception
        Inserts an embedded or linked OLE object as icon into the document. Allows to specify icon file and caption. 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.
        iconFile - Full path to the ICO file. If the value is null, Aspose.Words will use a predefined image.
        iconCaption - Icon caption. If the value is null, Aspose.Words will use the file name.
        Returns:
        Shape node containing Ole object and inserted at the current Builder position.

        Example:

        Shows how to insert an embedded or linked OLE object as icon into the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // If 'iconFile' and 'iconCaption' are omitted, this overloaded method selects
        // the icon according to 'progId' and uses the filename for the icon caption.
        builder.insertOleObjectAsIcon(getMyDir() + "Presentation.pptx", "Package", false, getImageDir() + "Logo icon.ico", "My embedded file");
        
        builder.insertBreak(BreakType.LINE_BREAK);
        
        try (FileInputStream stream = new FileInputStream(getMyDir() + "Presentation.pptx")) {
            // If 'iconFile' and 'iconCaption' are omitted, this overloaded method selects
            // the icon according to the file extension and uses the filename for the icon caption.
            Shape shape = builder.insertOleObjectAsIcon(stream, "PowerPoint.Application", getImageDir() + "Logo icon.ico",
                    "My embedded file stream");
        
            OlePackage setOlePackage = shape.getOleFormat().getOlePackage();
            setOlePackage.setFileName("Presentation.pptx");
            setOlePackage.setDisplayName("Presentation.pptx");
        }
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertOleObjectAsIcon.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:

        Shows how to insert an online video into a document using a URL.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.insertOnlineVideo("https://youtu.be/t_1LYZ102RA", 360.0, 270.0);
        
        // We can watch the video from Microsoft Word by clicking on the shape.
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertVideoWithUrl.docx");
      • 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.

        Example:

        Shows how to insert an online video into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        String videoUrl = "https://vimeo.com/52477838";
        
        // Insert a shape that plays a video from the web when clicked in Microsoft Word.
        // This rectangular shape will contain an image based on the first frame of the linked video
        // and a "play button" visual prompt. The video has an aspect ratio of 16:9.
        // We will set the shape's size to that ratio, so the image does not appear stretched.
        builder.insertOnlineVideo(videoUrl, RelativeHorizontalPosition.LEFT_MARGIN, 0.0,
                RelativeVerticalPosition.TOP_MARGIN, 0.0, 320.0, 180.0, WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertOnlineVideo.docx");
      • 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:

        Shows how to insert an online video into a document with a custom thumbnail.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        String videoUrl = "https://vimeo.com/52477838";
        String videoEmbedCode = "<iframe src=\"https://player.vimeo.com/video/52477838\" width=\"640\" height=\"360\" frameborder=\"0\" " +
                "title=\"Aspose\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";
        
        byte[] thumbnailImageBytes = IOUtils.toByteArray(getAsposelogoUri().toURL().openStream());
        
        BufferedImage image = ImageIO.read(new ByteArrayInputStream(thumbnailImageBytes));
        
        // Below are two ways of creating a shape with a custom thumbnail, which links to an online video
        // that will play when we click on the shape in Microsoft Word.
        // 1 -  Insert an inline shape at the builder's node insertion cursor:
        builder.insertOnlineVideo(videoUrl, videoEmbedCode, thumbnailImageBytes, image.getWidth(), image.getHeight());
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Insert a floating shape:
        double left = builder.getPageSetup().getRightMargin() - image.getWidth();
        double top = builder.getPageSetup().getBottomMargin() - image.getHeight();
        
        builder.insertOnlineVideo(videoUrl, videoEmbedCode, thumbnailImageBytes,
                RelativeHorizontalPosition.RIGHT_MARGIN, left, RelativeVerticalPosition.BOTTOM_MARGIN, top,
                image.getWidth(), image.getHeight(), WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertOnlineVideoCustomThumbnail.docx");
      • 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.

        Example:

        Shows how to insert an online video into a document with a custom thumbnail.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        String videoUrl = "https://vimeo.com/52477838";
        String videoEmbedCode = "<iframe src=\"https://player.vimeo.com/video/52477838\" width=\"640\" height=\"360\" frameborder=\"0\" " +
                "title=\"Aspose\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";
        
        byte[] thumbnailImageBytes = IOUtils.toByteArray(getAsposelogoUri().toURL().openStream());
        
        BufferedImage image = ImageIO.read(new ByteArrayInputStream(thumbnailImageBytes));
        
        // Below are two ways of creating a shape with a custom thumbnail, which links to an online video
        // that will play when we click on the shape in Microsoft Word.
        // 1 -  Insert an inline shape at the builder's node insertion cursor:
        builder.insertOnlineVideo(videoUrl, videoEmbedCode, thumbnailImageBytes, image.getWidth(), image.getHeight());
        
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // 2 -  Insert a floating shape:
        double left = builder.getPageSetup().getRightMargin() - image.getWidth();
        double top = builder.getPageSetup().getBottomMargin() - image.getHeight();
        
        builder.insertOnlineVideo(videoUrl, videoEmbedCode, thumbnailImageBytes,
                RelativeHorizontalPosition.RIGHT_MARGIN, left, RelativeVerticalPosition.BOTTOM_MARGIN, top,
                image.getWidth(), image.getHeight(), WrapType.SQUARE);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertOnlineVideoCustomThumbnail.docx");
      • 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);
        
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Arial");
        font.setUnderline(Underline.DASH);
        
        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
        paragraphFormat.setFirstLineIndent(8.0);
        paragraphFormat.setAlignment(ParagraphAlignment.JUSTIFY);
        paragraphFormat.setAddSpaceBetweenFarEastAndAlpha(true);
        paragraphFormat.setAddSpaceBetweenFarEastAndDigit(true);
        paragraphFormat.setKeepTogether(true);
        
        // The "Writeln" method ends the paragraph after appending text
        // and then starts a new line, adding a new paragraph.
        builder.writeln("Hello world!");
        
        Assert.assertTrue(builder.getCurrentParagraph().isEndOfDocument());
      • 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.

        Example:

        Shows how to insert DML shapes into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are two wrapping types that shapes may have.
        // 1 -  Floating:
        builder.insertShape(ShapeType.TOP_CORNERS_ROUNDED, RelativeHorizontalPosition.PAGE, 100.0,
                RelativeVerticalPosition.PAGE, 100.0, 50.0, 50.0, WrapType.NONE);
        
        // 2 -  Inline:
        builder.insertShape(ShapeType.DIAGONAL_CORNERS_ROUNDED, 50.0, 50.0);
        
        // If you need to create "non-primitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
        // TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, or DiagonalCornersRounded,
        // then save the document with "Strict" or "Transitional" compliance, which allows saving shape as DML.
        OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.DOCX);
        saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_TRANSITIONAL);
        
        doc.save(getArtifactsDir() + "Shape.ShapeInsertion.docx", saveOptions);
      • 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.

        Example:

        Shows how to insert DML shapes into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are two wrapping types that shapes may have.
        // 1 -  Floating:
        builder.insertShape(ShapeType.TOP_CORNERS_ROUNDED, RelativeHorizontalPosition.PAGE, 100.0,
                RelativeVerticalPosition.PAGE, 100.0, 50.0, 50.0, WrapType.NONE);
        
        // 2 -  Inline:
        builder.insertShape(ShapeType.DIAGONAL_CORNERS_ROUNDED, 50.0, 50.0);
        
        // If you need to create "non-primitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
        // TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, or DiagonalCornersRounded,
        // then save the document with "Strict" or "Transitional" compliance, which allows saving shape as DML.
        OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.DOCX);
        saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_TRANSITIONAL);
        
        doc.save(getArtifactsDir() + "Shape.ShapeInsertion.docx", saveOptions);
      • 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 a document with a personal certificate and a signature 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("Please sign here.");
        signatureLineOptions.setAllowComments(true);
        
        SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
        signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
        
        Assert.assertFalse(signatureLine.isSigned());
        Assert.assertFalse(signatureLine.isValid());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
        
        Date currentDate = new Date();
        
        SignOptions signOptions = new SignOptions();
        signOptions.setSignatureLineId(signatureLine.getId());
        signOptions.setProviderId(signatureLine.getProviderId());
        signOptions.setComments("Document was signed by vderyushev");
        signOptions.setSignTime(currentDate);
        
        CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
                getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
        
        // Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
        // indicating that the signature line contains a signature.
        doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
        Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
        signatureLine = shape.getSignatureLine();
        
        Assert.assertTrue(signatureLine.isSigned());
        Assert.assertTrue(signatureLine.isValid());
      • 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 an inline signature line into a document.
        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("Please sign here.");
        options.setAllowComments(true);
        
        builder.insertSignatureLine(options, RelativeHorizontalPosition.RIGHT_MARGIN, 2.0,
                RelativeVerticalPosition.PAGE, 3.0, WrapType.INLINE);
        
        // The signature line can be signed in Microsoft Word by double clicking it.
        doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineInline.docx");
      • 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.

        Example:

        Shows how to work with style separators.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Each paragraph can only have one style.
        // The InsertStyleSeparator method allows us to work around this limitation.
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        builder.write("This text is in a Heading style. ");
        builder.insertStyleSeparator();
        
        Style paraStyle = builder.getDocument().getStyles().add(StyleType.PARAGRAPH, "MyParaStyle");
        paraStyle.getFont().setBold(false);
        paraStyle.getFont().setSize(8.0);
        paraStyle.getFont().setName("Arial");
        
        builder.getParagraphFormat().setStyleName(paraStyle.getName());
        builder.write("This text is in a custom style. ");
        
        // Calling the InsertStyleSeparator method creates another paragraph,
        // which can have a different style to the previous. There will be no break between paragraphs.
        // The text in the output document will look like one paragraph with two styles.
        Assert.assertEquals(2, doc.getFirstSection().getBody().getParagraphs().getCount());
        Assert.assertEquals("Heading 1", doc.getFirstSection().getBody().getParagraphs().get(0).getParagraphFormat().getStyle().getName());
        Assert.assertEquals("MyParaStyle", doc.getFirstSection().getBody().getParagraphs().get(1).getParagraphFormat().getStyle().getName());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertStyleSeparator.docx");
      • 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:

        Shows how to insert a Table of contents (TOC) into a document using heading styles as entries.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a table of contents for the first page of the document.
        // Configure the table to pick up paragraphs with headings of levels 1 to 3.
        // Also, set its entries to be hyperlinks that will take us
        // to the location of the heading when left-clicked in Microsoft Word.
        builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // Populate the table of contents by adding paragraphs with heading styles.
        // Each such heading with a level between 1 and 3 will create an entry in the table.
        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_4);
        builder.writeln("Heading 3.1.3.1");
        builder.writeln("Heading 3.1.3.2");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        builder.writeln("Heading 3.2");
        builder.writeln("Heading 3.3");
        
        // A table of contents is a field of a type that needs to be updated to show an up-to-date result.
        doc.updateFields();
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertToc.docx");
      • 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:

        Shows how to create form fields.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Form fields are objects in the document that the user can interact with by being prompted to enter values.
        // We can create them using a document builder, and below are two ways of doing so.
        // 1 -  Basic text input:
        builder.insertTextInput("My text input", TextFormFieldType.REGULAR,
                "", "Enter your name here", 30);
        
        // 2 -  Combo box with prompt text, and a range of possible values:
        String[] items =
                {
                        "-- Select your favorite footwear --", "Sneakers", "Oxfords", "Flip-flops", "Other"
                };
        
        builder.insertParagraph();
        builder.insertComboBox("My combo box", items, 0);
        
        builder.getDocument().save(getArtifactsDir() + "DocumentBuilder.CreateForm.docx");

        Example:

        Shows how to insert a text input form field.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.write("Please enter text here: ");
        
        // Insert a text input field, which will allow the user to click it and enter text.
        // Assign some placeholder text that the user may overwrite and pass
        // a maximum text length of 0 to apply no limit on the form field's contents.
        builder.insertTextInput("TextInput1", TextFormFieldType.REGULAR, "", "Placeholder text", 0);
        
        // The form field will appear in the form of an "input" html tag, with a type of "text".
        doc.save(getArtifactsDir() + "FormFields.TextInput.html");

        Example:

        Shows how to insert a text input form field into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a form that prompts the user to enter text.
        builder.insertTextInput("TextInput", TextFormFieldType.REGULAR, "", "Enter your text here", 0);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertTextInput.docx");
      • 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 a document builder's cursor to different nodes in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a valid bookmark, an entity that consists of nodes enclosed by a bookmark start node,
        // and a bookmark end node. 
        builder.startBookmark("MyBookmark");
        builder.write("Bookmark contents.");
        builder.endBookmark("MyBookmark");
        
        NodeCollection firstParagraphNodes = doc.getFirstSection().getBody().getFirstParagraph().getChildNodes();
        
        Assert.assertEquals(NodeType.BOOKMARK_START, firstParagraphNodes.get(0).getNodeType());
        Assert.assertEquals(NodeType.RUN, firstParagraphNodes.get(1).getNodeType());
        Assert.assertEquals("Bookmark contents.", firstParagraphNodes.get(1).getText().trim());
        Assert.assertEquals(NodeType.BOOKMARK_END, firstParagraphNodes.get(2).getNodeType());
        
        // The document builder's cursor is always ahead of the node that we last added with it.
        // If the builder's cursor is at the end of the document, its current node will be null.
        // The previous node is the bookmark end node that we last added.
        // Adding new nodes with the builder will append them to the last node.
        Assert.assertNull(builder.getCurrentNode());
        
        // If we wish to edit a different part of the document with the builder,
        // we will need to bring its cursor to the node we wish to edit.
        builder.moveToBookmark("MyBookmark");
        
        // Moving it to a bookmark will move it to the first node within the bookmark start and end nodes, the enclosed run.
        Assert.assertEquals(firstParagraphNodes.get(1), builder.getCurrentNode());
        
        // We can also move the cursor to an individual node like this.
        builder.moveTo(doc.getFirstSection().getBody().getFirstParagraph().getChildNodes(NodeType.ANY, false).get(0));
        
        Assert.assertEquals(NodeType.BOOKMARK_START, builder.getCurrentNode().getNodeType());
        Assert.assertEquals(doc.getFirstSection().getBody().getFirstParagraph(), builder.getCurrentParagraph());
        Assert.assertTrue(builder.isAtStartOfParagraph());
        
        // We can use specific methods to move to the start/end of a document.
        builder.moveToDocumentEnd();
        
        Assert.assertTrue(builder.isAtEndOfParagraph());
        
        builder.moveToDocumentStart();
        
        Assert.assertTrue(builder.isAtStartOfParagraph());

        Example:

        Shows how to move a DocumentBuilder's cursor position to a specified node.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Run 1. ");
        
        // The document builder has a cursor, which acts as the part of the document
        // where the builder appends new nodes when we use its document construction methods.
        // This cursor functions in the same way as Microsoft Word's blinking cursor,
        // and it also always ends up immediately after any node that the builder just inserted.
        // To append content to a different part of the document,
        // we can move the cursor to a different node with the "MoveTo" method.
        builder.moveTo(doc.getFirstSection().getBody().getFirstParagraph().getRuns().get(0));
        
        // The cursor is now in front of the node that we moved it to.
        // Adding a second run will insert it in front of the first run.
        builder.writeln("Run 2. ");
        
        Assert.assertEquals("Run 2. \rRun 1.", doc.getText().trim());
        
        // Move the cursor to the end of the document to continue appending text to the end as before.
        builder.moveTo(doc.getLastSection().getBody().getLastParagraph());
        builder.writeln("Run 3. ");
        
        Assert.assertEquals("Run 2. \rRun 1. \rRun 3.", doc.getText().trim());
      • 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 a document builder's cursor to different nodes in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a valid bookmark, an entity that consists of nodes enclosed by a bookmark start node,
        // and a bookmark end node. 
        builder.startBookmark("MyBookmark");
        builder.write("Bookmark contents.");
        builder.endBookmark("MyBookmark");
        
        NodeCollection firstParagraphNodes = doc.getFirstSection().getBody().getFirstParagraph().getChildNodes();
        
        Assert.assertEquals(NodeType.BOOKMARK_START, firstParagraphNodes.get(0).getNodeType());
        Assert.assertEquals(NodeType.RUN, firstParagraphNodes.get(1).getNodeType());
        Assert.assertEquals("Bookmark contents.", firstParagraphNodes.get(1).getText().trim());
        Assert.assertEquals(NodeType.BOOKMARK_END, firstParagraphNodes.get(2).getNodeType());
        
        // The document builder's cursor is always ahead of the node that we last added with it.
        // If the builder's cursor is at the end of the document, its current node will be null.
        // The previous node is the bookmark end node that we last added.
        // Adding new nodes with the builder will append them to the last node.
        Assert.assertNull(builder.getCurrentNode());
        
        // If we wish to edit a different part of the document with the builder,
        // we will need to bring its cursor to the node we wish to edit.
        builder.moveToBookmark("MyBookmark");
        
        // Moving it to a bookmark will move it to the first node within the bookmark start and end nodes, the enclosed run.
        Assert.assertEquals(firstParagraphNodes.get(1), builder.getCurrentNode());
        
        // We can also move the cursor to an individual node like this.
        builder.moveTo(doc.getFirstSection().getBody().getFirstParagraph().getChildNodes(NodeType.ANY, false).get(0));
        
        Assert.assertEquals(NodeType.BOOKMARK_START, builder.getCurrentNode().getNodeType());
        Assert.assertEquals(doc.getFirstSection().getBody().getFirstParagraph(), builder.getCurrentParagraph());
        Assert.assertTrue(builder.isAtStartOfParagraph());
        
        // We can use specific methods to move to the start/end of a document.
        builder.moveToDocumentEnd();
        
        Assert.assertTrue(builder.isAtEndOfParagraph());
        
        builder.moveToDocumentStart();
        
        Assert.assertTrue(builder.isAtStartOfParagraph());
      • 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 document builder's node insertion point cursor to a bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // A valid bookmark consists of a BookmarkStart node, a BookmarkEnd node with a
        // matching bookmark name somewhere afterward, and contents enclosed by those nodes.
        builder.startBookmark("MyBookmark");
        builder.write("Hello world! ");
        builder.endBookmark("MyBookmark");
        
        // There are 4 ways of moving a document builder's cursor to a bookmark.
        // If we are between the BookmarkStart and BookmarkEnd nodes, the cursor will be inside the bookmark.
        // This means that any text added by the builder will become a part of the bookmark.
        // 1 -  Outside of the bookmark, in front of the BookmarkStart node:
        Assert.assertTrue(builder.moveToBookmark("MyBookmark", true, false));
        builder.write("1. ");
        
        Assert.assertEquals("Hello world! ", doc.getRange().getBookmarks().get("MyBookmark").getText());
        Assert.assertEquals("1. Hello world!", doc.getText().trim());
        
        // 2 -  Inside the bookmark, right after the BookmarkStart node:
        Assert.assertTrue(builder.moveToBookmark("MyBookmark", true, true));
        builder.write("2. ");
        
        Assert.assertEquals("2. Hello world! ", doc.getRange().getBookmarks().get("MyBookmark").getText());
        Assert.assertEquals("1. 2. Hello world!", doc.getText().trim());
        
        // 2 -  Inside the bookmark, right in front of the BookmarkEnd node:
        Assert.assertTrue(builder.moveToBookmark("MyBookmark", false, false));
        builder.write("3. ");
        
        Assert.assertEquals("2. Hello world! 3. ", doc.getRange().getBookmarks().get("MyBookmark").getText());
        Assert.assertEquals("1. 2. Hello world! 3.", doc.getText().trim());
        
        // 4 -  Outside of the bookmark, after the BookmarkEnd node:
        Assert.assertTrue(builder.moveToBookmark("MyBookmark", false, true));
        builder.write("4.");
        
        Assert.assertEquals("2. Hello world! 3. ", doc.getRange().getBookmarks().get("MyBookmark").getText());
        Assert.assertEquals("1. 2. Hello world! 3. 4.", doc.getText().trim());
      • 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. A negative value allows you to specify a position from the end of the cell. Use -1 to move to the end of the cell.

        Example:

        Shows how to move a document builder's cursor to a cell in a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create an empty 2x2 table.
        builder.startTable();
        builder.insertCell();
        builder.insertCell();
        builder.endRow();
        builder.insertCell();
        builder.insertCell();
        builder.endTable();
        
        // Because we have ended the table with the EndTable method,
        // the document builder's cursor is currently outside the table.
        // This cursor has the same function as Microsoft Word's blinking text cursor.
        // It can also be moved to a different location in the document using the builder's MoveTo methods.
        // We can move the cursor back inside the table to a specific cell.
        builder.moveToCell(0, 1, 1, 0);
        builder.write("Column 2, cell 2.");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.MoveToCell.docx");
      • moveToDocumentEnd

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

        Example:

        Shows how to move a document builder's cursor to different nodes in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a valid bookmark, an entity that consists of nodes enclosed by a bookmark start node,
        // and a bookmark end node. 
        builder.startBookmark("MyBookmark");
        builder.write("Bookmark contents.");
        builder.endBookmark("MyBookmark");
        
        NodeCollection firstParagraphNodes = doc.getFirstSection().getBody().getFirstParagraph().getChildNodes();
        
        Assert.assertEquals(NodeType.BOOKMARK_START, firstParagraphNodes.get(0).getNodeType());
        Assert.assertEquals(NodeType.RUN, firstParagraphNodes.get(1).getNodeType());
        Assert.assertEquals("Bookmark contents.", firstParagraphNodes.get(1).getText().trim());
        Assert.assertEquals(NodeType.BOOKMARK_END, firstParagraphNodes.get(2).getNodeType());
        
        // The document builder's cursor is always ahead of the node that we last added with it.
        // If the builder's cursor is at the end of the document, its current node will be null.
        // The previous node is the bookmark end node that we last added.
        // Adding new nodes with the builder will append them to the last node.
        Assert.assertNull(builder.getCurrentNode());
        
        // If we wish to edit a different part of the document with the builder,
        // we will need to bring its cursor to the node we wish to edit.
        builder.moveToBookmark("MyBookmark");
        
        // Moving it to a bookmark will move it to the first node within the bookmark start and end nodes, the enclosed run.
        Assert.assertEquals(firstParagraphNodes.get(1), builder.getCurrentNode());
        
        // We can also move the cursor to an individual node like this.
        builder.moveTo(doc.getFirstSection().getBody().getFirstParagraph().getChildNodes(NodeType.ANY, false).get(0));
        
        Assert.assertEquals(NodeType.BOOKMARK_START, builder.getCurrentNode().getNodeType());
        Assert.assertEquals(doc.getFirstSection().getBody().getFirstParagraph(), builder.getCurrentParagraph());
        Assert.assertTrue(builder.isAtStartOfParagraph());
        
        // We can use specific methods to move to the start/end of a document.
        builder.moveToDocumentEnd();
        
        Assert.assertTrue(builder.isAtEndOfParagraph());
        
        builder.moveToDocumentStart();
        
        Assert.assertTrue(builder.isAtStartOfParagraph());
      • moveToDocumentStart

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

        Example:

        Shows how to move a document builder's cursor to different nodes in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a valid bookmark, an entity that consists of nodes enclosed by a bookmark start node,
        // and a bookmark end node. 
        builder.startBookmark("MyBookmark");
        builder.write("Bookmark contents.");
        builder.endBookmark("MyBookmark");
        
        NodeCollection firstParagraphNodes = doc.getFirstSection().getBody().getFirstParagraph().getChildNodes();
        
        Assert.assertEquals(NodeType.BOOKMARK_START, firstParagraphNodes.get(0).getNodeType());
        Assert.assertEquals(NodeType.RUN, firstParagraphNodes.get(1).getNodeType());
        Assert.assertEquals("Bookmark contents.", firstParagraphNodes.get(1).getText().trim());
        Assert.assertEquals(NodeType.BOOKMARK_END, firstParagraphNodes.get(2).getNodeType());
        
        // The document builder's cursor is always ahead of the node that we last added with it.
        // If the builder's cursor is at the end of the document, its current node will be null.
        // The previous node is the bookmark end node that we last added.
        // Adding new nodes with the builder will append them to the last node.
        Assert.assertNull(builder.getCurrentNode());
        
        // If we wish to edit a different part of the document with the builder,
        // we will need to bring its cursor to the node we wish to edit.
        builder.moveToBookmark("MyBookmark");
        
        // Moving it to a bookmark will move it to the first node within the bookmark start and end nodes, the enclosed run.
        Assert.assertEquals(firstParagraphNodes.get(1), builder.getCurrentNode());
        
        // We can also move the cursor to an individual node like this.
        builder.moveTo(doc.getFirstSection().getBody().getFirstParagraph().getChildNodes(NodeType.ANY, false).get(0));
        
        Assert.assertEquals(NodeType.BOOKMARK_START, builder.getCurrentNode().getNodeType());
        Assert.assertEquals(doc.getFirstSection().getBody().getFirstParagraph(), builder.getCurrentParagraph());
        Assert.assertTrue(builder.isAtStartOfParagraph());
        
        // We can use specific methods to move to the start/end of a document.
        builder.moveToDocumentEnd();
        
        Assert.assertTrue(builder.isAtEndOfParagraph());
        
        builder.moveToDocumentStart();
        
        Assert.assertTrue(builder.isAtStartOfParagraph());
      • 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 a document builder's node insertion point cursor to a specific field.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a field using the DocumentBuilder and add a run of text after it.
        Field field = builder.insertField(" AUTHOR \"John Doe\" ");
        
        // The builder's cursor is currently at end of the document.
        Assert.assertNull(builder.getCurrentNode());
        
        // Move the cursor to the field while specifying whether to place that cursor before or after the field.
        builder.moveToField(field, moveCursorToAfterTheField);
        
        // Note that the cursor is outside of the field in both cases.
        // This means that we cannot edit the field using the builder like this.
        // To edit a field, we can use the builder's MoveTo method on a field's FieldStart
        // or FieldSeparator node to place the cursor inside.
        if (moveCursorToAfterTheField) {
            Assert.assertNull(builder.getCurrentNode());
            builder.write(" Text immediately after the field.");
        
            Assert.assertEquals("AUTHOR \"John Doe\" \u0014John Doe\u0015 Text immediately after the field.",
                    doc.getText().trim());
        } else {
            Assert.assertEquals(field.getStart(), builder.getCurrentNode());
            builder.write("Text immediately before the field. ");
        
            Assert.assertEquals("Text immediately before the field. \u0013 AUTHOR \"John Doe\" \u0014John Doe",
                    doc.getText().trim());
        }
      • 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:

        Shows how to create headers and footers in a document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want different headers and footers for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers, then add three pages to the document to display each header type.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header for the first page");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header for even pages");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header for all other pages");
        
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.HeadersAndFooters.docx");

        Example:

        Shows how to insert an image, and use it as a watermark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert the image into the header so that it will be visible on every page.
        BufferedImage image = ImageIO.read(new File(getImageDir() + "Transparent background logo.png"));
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        Shape shape = builder.insertImage(image);
        shape.setWrapType(WrapType.NONE);
        shape.setBehindText(true);
        
        // Place the image at the center of the page.
        shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        shape.setLeft((builder.getPageSetup().getPageWidth() - shape.getWidth()) / 2.0);
        shape.setTop((builder.getPageSetup().getPageHeight() - shape.getHeight()) / 2.0);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertWatermark.docx");
      • 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.
        public void insertCheckBox() throws Exception {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            builder.startTable();
            builder.insertCell();
            builder.insertField(" MERGEFIELD  TableStart:StudentCourse ");
            builder.insertCell();
            builder.insertField(" MERGEFIELD  CourseName ");
            builder.insertCell();
            builder.insertField(" MERGEFIELD  TableEnd:StudentCourse ");
            builder.endTable();
        
            // 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(getArtifactsDir() + "MailMergeEvent.InsertCheckBox.docx");
        }
        
        private class HandleMergeFieldInsertCheckBox implements IFieldMergingCallback {
            /**
             * This is called for each merge field in the document
             * when Document.MailMerge.ExecuteWithRegions is called.
             */
            public void fieldMerging(final FieldMergingArgs args) throws Exception {
                if (args.getDocumentFieldName().equals("CourseName")) {
                    // The name of the table that we are merging can be found here
                    Assert.assertEquals(args.getTableName(), "StudentCourse");
        
                    // Insert the checkbox for this merge field, using DocumentBuilder
                    DocumentBuilder builder = new DocumentBuilder(args.getDocument());
                    builder.moveToMergeField(args.getFieldName());
                    builder.insertCheckBox(args.getDocumentFieldName() + mCheckBoxCount, false, 0);
                    // Get the actual value of the field
                    String fieldValue = args.getFieldValue().toString();
        
                    // In this case, for every record index 'n', the corresponding field value is "Course n"
                    Assert.assertEquals(args.getRecordIndex(), Character.getNumericValue(fieldValue.charAt(7)));
        
                    builder.write(fieldValue);
                    mCheckBoxCount++;
                }
            }
        
            public void imageFieldMerging(final 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 " + i);
            }
            return dataTable;
        }

        Example:

        Shows how to fill MERGEFIELDs with data with a document builder instead of a mail merge.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert some MERGEFIELDS, which accept data from columns of the same name in a data source during a mail merge,
        // and then fill them manually.
        builder.insertField(" MERGEFIELD Chairman ");
        builder.insertField(" MERGEFIELD ChiefFinancialOfficer ");
        builder.insertField(" MERGEFIELD ChiefTechnologyOfficer ");
        
        builder.moveToMergeField("Chairman");
        builder.setBold(true);
        builder.writeln("John Doe");
        
        builder.moveToMergeField("ChiefFinancialOfficer");
        builder.setItalic(true);
        builder.writeln("Jane Doe");
        
        builder.moveToMergeField("ChiefTechnologyOfficer");
        builder.setItalic(true);
        builder.writeln("John Bloggs");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.FillMergeFields.docx");
      • 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.

        Example:

        Shows how to insert fields, and move the document builder's cursor to them.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.insertField("MERGEFIELD MyMergeField1 \\* MERGEFORMAT");
        builder.insertField("MERGEFIELD MyMergeField2 \\* MERGEFORMAT");
        
        // Move the cursor to the first MERGEFIELD.
        builder.moveToMergeField("MyMergeField1", true, false);
        
        // Note that the cursor is placed immediately after the first MERGEFIELD, and before the second.
        Assert.assertEquals(doc.getRange().getFields().get(1).getStart(), builder.getCurrentNode());
        Assert.assertEquals(doc.getRange().getFields().get(0).getEnd(), builder.getCurrentNode().getPreviousSibling());
        
        // If we wish to edit the field's field code or contents using the builder,
        // its cursor would need to be inside a field.
        // To place it inside a field, we would need to call the document builder's MoveTo method
        // and pass the field's start or separator node as an argument.
        builder.write(" Text between our merge fields. ");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.MergeFields.docx");
      • 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. A negative value allows you to specify a position from the end of the paragraph. Use -1 to move to the end of the paragraph.

        Example:

        Shows how to move a builder's cursor position to a specified paragraph.
        Document doc = new Document(getMyDir() + "Paragraphs.docx");
        ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
        
        Assert.assertEquals(22, paragraphs.getCount());
        
        // Create document builder to edit the document. The builder's cursor,
        // which is the point where it will insert new nodes when we call its document construction methods,
        // is currently at the beginning of the document.
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Assert.assertEquals(0, paragraphs.indexOf(builder.getCurrentParagraph()));
        
        // Move that cursor to a different paragraph will place that cursor in front of that paragraph.
        builder.moveToParagraph(2, 0);
        
        // Any new content that we add will be inserted at that point.
        builder.writeln("This is a new third 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:

        Shows how to create headers and footers in a document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want different headers and footers for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers, then add three pages to the document to display each header type.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header for the first page");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header for even pages");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header for all other pages");
        
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.HeadersAndFooters.docx");
      • popFont

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

        Example:

        Shows how to use a document builder's formatting stack.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set up font formatting, then write the text that goes before the hyperlink.
        builder.getFont().setName("Arial");
        builder.getFont().setSize(24.0);
        builder.write("To visit Google, hold Ctrl and click ");
        
        // Preserve our current formatting configuration on the stack.
        builder.pushFont();
        
        // Alter the builder's current formatting by applying a new style.
        builder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
        builder.insertHyperlink("here", "http://www.google.com", false);
        
        Assert.assertEquals(Color.BLUE.getRGB(), builder.getFont().getColor().getRGB());
        Assert.assertEquals(Underline.SINGLE, builder.getFont().getUnderline());
        
        // Restore the font formatting that we saved earlier and remove the element from the stack.
        builder.popFont();
        
        Assert.assertEquals(0, builder.getFont().getColor().getRGB());
        Assert.assertEquals(Underline.NONE, builder.getFont().getUnderline());
        
        builder.write(". We hope you enjoyed the example.");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.PushPopFont.docx");
      • pushFont

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

        Example:

        Shows how to use a document builder's formatting stack.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set up font formatting, then write the text that goes before the hyperlink.
        builder.getFont().setName("Arial");
        builder.getFont().setSize(24.0);
        builder.write("To visit Google, hold Ctrl and click ");
        
        // Preserve our current formatting configuration on the stack.
        builder.pushFont();
        
        // Alter the builder's current formatting by applying a new style.
        builder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
        builder.insertHyperlink("here", "http://www.google.com", false);
        
        Assert.assertEquals(Color.BLUE.getRGB(), builder.getFont().getColor().getRGB());
        Assert.assertEquals(Underline.SINGLE, builder.getFont().getUnderline());
        
        // Restore the font formatting that we saved earlier and remove the element from the stack.
        builder.popFont();
        
        Assert.assertEquals(0, builder.getFont().getColor().getRGB());
        Assert.assertEquals(Underline.NONE, builder.getFont().getUnderline());
        
        builder.write(". We hope you enjoyed the example.");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.PushPopFont.docx");
      • 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:

        Shows how to insert a hyperlink which references a local bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startBookmark("Bookmark1");
        builder.write("Bookmarked text. ");
        builder.endBookmark("Bookmark1");
        builder.writeln("Text outside of the bookmark.");
        
        // Insert a HYPERLINK field that links to the bookmark. We can pass field switches
        // to the "InsertHyperlink" method as part of the argument containing the referenced bookmark's name.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        builder.insertHyperlink("Link to Bookmark1", "Bookmark1\" \\o \"Hyperlink Tip", true);
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertHyperlinkToLocalBookmark.docx");

        Example:

        Shows how create a bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // A valid bookmark needs to have document body text enclosed by
        // BookmarkStart and BookmarkEnd nodes created with a matching bookmark name.
        builder.startBookmark("MyBookmark");
        builder.writeln("Hello world!");
        builder.endBookmark("MyBookmark");
        
        Assert.assertEquals(1, doc.getRange().getBookmarks().getCount());
        Assert.assertEquals("MyBookmark", doc.getRange().getBookmarks().get(0).getName());
        Assert.assertEquals("Hello world!", doc.getRange().getBookmarks().get(0).getText().trim());
      • startColumnBookmark

        public BookmarkStart startColumnBookmark(java.lang.String bookmarkName)
        Marks the current position in the document as a column bookmark start. The position must be in a table cell.

        A column bookmark covers one or more columns in a range of rows. To create a valid bookmark you need to call both startColumnBookmark(java.lang.String) and endColumnBookmark(java.lang.String) with the same bookmarkName parameter.

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

        The actual position of the inserted BookmarkStart node may differ from the current document builder position.

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

        Example:

        Shows how to create a column bookmark.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        
        builder.insertCell();
        // Cells 1,2,4,5 will be bookmarked.
        builder.startColumnBookmark("MyBookmark_1");
        // Badly formed bookmarks or bookmarks with duplicate names will be ignored when the document is saved.
        builder.startColumnBookmark("MyBookmark_1");
        builder.startColumnBookmark("BadStartBookmark");
        builder.write("Cell 1");
        
        builder.insertCell();
        builder.write("Cell 2");
        
        builder.insertCell();
        builder.write("Cell 3");
        
        builder.endRow();
        
        builder.insertCell();
        builder.write("Cell 4");
        
        builder.insertCell();
        builder.write("Cell 5");
        builder.endColumnBookmark("MyBookmark_1");
        builder.endColumnBookmark("MyBookmark_1");
        
        builder.insertCell();
        builder.write("Cell 6");
        
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "Bookmarks.CreateColumnBookmark.docx");
      • 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 work with an editable range.
        Document doc = new Document();
        doc.protect(ProtectionType.READ_ONLY, "MyPassword");
        
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world! Since we have set the document's protection level to read-only," +
                " we cannot edit this paragraph without the password.");
        
        // Editable ranges allow us to leave parts of protected documents open for editing.
        EditableRangeStart editableRangeStart = builder.startEditableRange();
        builder.writeln("This paragraph is inside an editable range, and can be edited.");
        EditableRangeEnd editableRangeEnd = builder.endEditableRange();
        
        // A well-formed editable range has a start node, and end node.
        // These nodes have matching IDs and encompass editable nodes.
        EditableRange editableRange = editableRangeStart.getEditableRange();
        
        Assert.assertEquals(editableRangeStart.getId(), editableRange.getId());
        Assert.assertEquals(editableRangeEnd.getId(), editableRange.getId());
        
        // Different parts of the editable range link to each other.
        Assert.assertEquals(editableRangeStart.getId(), editableRange.getEditableRangeStart().getId());
        Assert.assertEquals(editableRangeStart.getId(), editableRangeEnd.getEditableRangeStart().getId());
        Assert.assertEquals(editableRange.getId(), editableRangeStart.getEditableRange().getId());
        Assert.assertEquals(editableRangeEnd.getId(), editableRange.getEditableRangeEnd().getId());
        
        // We can access the node types of each part like this. The editable range itself is not a node,
        // but an entity which consists of a start, an end, and their enclosed contents.
        Assert.assertEquals(NodeType.EDITABLE_RANGE_START, editableRangeStart.getNodeType());
        Assert.assertEquals(NodeType.EDITABLE_RANGE_END, editableRangeEnd.getNodeType());
        
        builder.writeln("This paragraph is outside the editable range, and cannot be edited.");
        
        doc.save(getArtifactsDir() + "EditableRange.CreateAndRemove.docx");
        
        // Remove an editable range. All the nodes that were inside the range will remain intact.
        editableRange.remove();

        Example:

        Shows how to create nested editable ranges.
        Document doc = new Document();
        doc.protect(ProtectionType.READ_ONLY, "MyPassword");
        
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world! Since we have set the document's protection level to read-only, " +
                "we cannot edit this paragraph without the password.");
        
        // Create two nested editable ranges.
        EditableRangeStart outerEditableRangeStart = builder.startEditableRange();
        builder.writeln("This paragraph inside the outer editable range and can be edited.");
        
        EditableRangeStart innerEditableRangeStart = builder.startEditableRange();
        builder.writeln("This paragraph inside both the outer and inner editable ranges and can be edited.");
        
        // Currently, the document builder's node insertion cursor is in more than one ongoing editable range.
        // When we want to end an editable range in this situation,
        // we need to specify which of the ranges we wish to end by passing its EditableRangeStart node.
        builder.endEditableRange(innerEditableRangeStart);
        
        builder.writeln("This paragraph inside the outer editable range and can be edited.");
        
        builder.endEditableRange(outerEditableRangeStart);
        
        builder.writeln("This paragraph is outside any editable ranges, and cannot be edited.");
        
        // If a region of text has two overlapping editable ranges with specified groups,
        // the combined group of users excluded by both groups are prevented from editing it.
        outerEditableRangeStart.getEditableRange().setEditorGroup(EditorType.EVERYONE);
        innerEditableRangeStart.getEditableRange().setEditorGroup(EditorType.CONTRIBUTORS);
        
        doc.save(getArtifactsDir() + "EditableRange.Nested.docx");
      • 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 2x2 table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("Row 1, cell 1.");
        builder.insertCell();
        builder.write("Row 1, cell 2.");
        builder.endRow();
        
        // While building the table, the document builder will apply its current RowFormat/CellFormat property values
        // to the current row/cell that its cursor is in and any new rows/cells as it creates them.
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(0).getCellFormat().getVerticalAlignment());
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(1).getCellFormat().getVerticalAlignment());
        
        builder.insertCell();
        builder.getRowFormat().setHeight(100.0);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 2, cell 1.");
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 2, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
        Assert.assertEquals(0.0, table.getRows().get(0).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.AUTO, table.getRows().get(0).getRowFormat().getHeightRule());
        Assert.assertEquals(100.0, table.getRows().get(1).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.EXACTLY, table.getRows().get(1).getRowFormat().getHeightRule());
        Assert.assertEquals(TextOrientation.UPWARD, table.getRows().get(1).getCells().get(0).getCellFormat().getOrientation());
        Assert.assertEquals(TextOrientation.DOWNWARD, table.getRows().get(1).getCells().get(1).getCellFormat().getOrientation());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.BuildTable.docx");

        Example:

        Shows how to format cells with a document builder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Row 1, cell 1.");
        
        // Insert a second cell, and then configure cell text padding options.
        // The builder will apply these settings at its current cell, and any new cells creates afterwards.
        builder.insertCell();
        
        CellFormat cellFormat = builder.getCellFormat();
        cellFormat.setWidth(250.0);
        cellFormat.setLeftPadding(30.0);
        cellFormat.setRightPadding(30.0);
        cellFormat.setTopPadding(30.0);
        cellFormat.setBottomPadding(30.0);
        
        builder.write("Row 1, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // The first cell was unaffected by the padding reconfiguration, and still holds the default values.
        Assert.assertEquals(0.0d, table.getFirstRow().getCells().get(0).getCellFormat().getWidth());
        Assert.assertEquals(5.4d, table.getFirstRow().getCells().get(0).getCellFormat().getLeftPadding());
        Assert.assertEquals(5.4d, table.getFirstRow().getCells().get(0).getCellFormat().getRightPadding());
        Assert.assertEquals(0.0d, table.getFirstRow().getCells().get(0).getCellFormat().getTopPadding());
        Assert.assertEquals(0.0d, table.getFirstRow().getCells().get(0).getCellFormat().getBottomPadding());
        
        Assert.assertEquals(250.0d, table.getFirstRow().getCells().get(1).getCellFormat().getWidth());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getLeftPadding());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getRightPadding());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getTopPadding());
        Assert.assertEquals(30.0d, table.getFirstRow().getCells().get(1).getCellFormat().getBottomPadding());
        
        // The first cell will still grow in the output document to match the size of its neighboring cell.
        doc.save(getArtifactsDir() + "DocumentBuilder.SetCellFormatting.docx");

        Example:

        Shows how to build a table with custom borders.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        
        // Setting table formatting options for a document builder
        // will apply them to every row and cell that we add with it.
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        
        builder.getCellFormat().clearFormatting();
        builder.getCellFormat().setWidth(150.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.getCellFormat().setWrapText(false);
        builder.getCellFormat().setFitText(true);
        
        builder.getRowFormat().clearFormatting();
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getRowFormat().setHeight(50.0);
        builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D);
        builder.getRowFormat().getBorders().setColor(Color.ORANGE);
        
        builder.insertCell();
        builder.write("Row 1, Col 1");
        
        builder.insertCell();
        builder.write("Row 1, Col 2");
        builder.endRow();
        
        // Changing the formatting will apply it to the current cell,
        // and any new cells that we create with the builder afterward.
        // This will not affect the cells that we have added previously.
        builder.getCellFormat().getShading().clearFormatting();
        
        builder.insertCell();
        builder.write("Row 2, Col 1");
        
        builder.insertCell();
        builder.write("Row 2, Col 2");
        
        builder.endRow();
        
        // Increase row height to fit the vertical text.
        builder.insertCell();
        builder.getRowFormat().setHeight(150.0);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 3, Col 1");
        
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 3, Col 2");
        
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");
      • 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 build a formatted 2x2 table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("Row 1, cell 1.");
        builder.insertCell();
        builder.write("Row 1, cell 2.");
        builder.endRow();
        
        // While building the table, the document builder will apply its current RowFormat/CellFormat property values
        // to the current row/cell that its cursor is in and any new rows/cells as it creates them.
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(0).getCellFormat().getVerticalAlignment());
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(1).getCellFormat().getVerticalAlignment());
        
        builder.insertCell();
        builder.getRowFormat().setHeight(100.0);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 2, cell 1.");
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 2, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
        Assert.assertEquals(0.0, table.getRows().get(0).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.AUTO, table.getRows().get(0).getRowFormat().getHeightRule());
        Assert.assertEquals(100.0, table.getRows().get(1).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.EXACTLY, table.getRows().get(1).getRowFormat().getHeightRule());
        Assert.assertEquals(TextOrientation.UPWARD, table.getRows().get(1).getCells().get(0).getCellFormat().getOrientation());
        Assert.assertEquals(TextOrientation.DOWNWARD, table.getRows().get(1).getCells().get(1).getCellFormat().getOrientation());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.BuildTable.docx");

        Example:

        Shows how to build a table with custom borders.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.startTable();
        
        // Setting table formatting options for a document builder
        // will apply them to every row and cell that we add with it.
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        
        builder.getCellFormat().clearFormatting();
        builder.getCellFormat().setWidth(150.0);
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.getCellFormat().setWrapText(false);
        builder.getCellFormat().setFitText(true);
        
        builder.getRowFormat().clearFormatting();
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getRowFormat().setHeight(50.0);
        builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D);
        builder.getRowFormat().getBorders().setColor(Color.ORANGE);
        
        builder.insertCell();
        builder.write("Row 1, Col 1");
        
        builder.insertCell();
        builder.write("Row 1, Col 2");
        builder.endRow();
        
        // Changing the formatting will apply it to the current cell,
        // and any new cells that we create with the builder afterward.
        // This will not affect the cells that we have added previously.
        builder.getCellFormat().getShading().clearFormatting();
        
        builder.insertCell();
        builder.write("Row 2, Col 1");
        
        builder.insertCell();
        builder.write("Row 2, Col 2");
        
        builder.endRow();
        
        // Increase row height to fit the vertical text.
        builder.insertCell();
        builder.getRowFormat().setHeight(150.0);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 3, Col 1");
        
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 3, Col 2");
        
        builder.endRow();
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");

        Example:

        Shows how to use a document builder to create a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Start the table, then populate the first row with two cells.
        builder.startTable();
        builder.insertCell();
        builder.write("Row 1, Cell 1.");
        builder.insertCell();
        builder.write("Row 1, Cell 2.");
        
        // Call the builder's "EndRow" method to start a new row.
        builder.endRow();
        builder.insertCell();
        builder.write("Row 2, Cell 1.");
        builder.insertCell();
        builder.write("Row 2, Cell 2.");
        builder.endTable();
        
        doc.save(getArtifactsDir() + "DocumentBuilder.CreateTable.docx");

        Example:

        Shows how to insert a string surrounded by a border into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().getBorder().setColor(Color.GREEN);
        builder.getFont().getBorder().setLineWidth(2.5);
        builder.getFont().getBorder().setLineStyle(LineStyle.DASH_DOT_STROKER);
        
        builder.write("Text surrounded by green border.");
        
        doc.save(getArtifactsDir() + "Border.FontBorder.docx");
      • writeln

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

        Calls insertParagraph().

        Example:

        Shows how to create headers and footers in a document using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify that we want different headers and footers for first, even and odd pages.
        builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
        builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
        
        // Create the headers, then add three pages to the document to display each header type.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
        builder.write("Header for the first page");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
        builder.write("Header for even pages");
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.write("Header for all other pages");
        
        builder.moveToSection(0);
        builder.writeln("Page1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Page3");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.HeadersAndFooters.docx");
      • 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 2x2 table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
        builder.write("Row 1, cell 1.");
        builder.insertCell();
        builder.write("Row 1, cell 2.");
        builder.endRow();
        
        // While building the table, the document builder will apply its current RowFormat/CellFormat property values
        // to the current row/cell that its cursor is in and any new rows/cells as it creates them.
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(0).getCellFormat().getVerticalAlignment());
        Assert.assertEquals(CellVerticalAlignment.CENTER, table.getRows().get(0).getCells().get(1).getCellFormat().getVerticalAlignment());
        
        builder.insertCell();
        builder.getRowFormat().setHeight(100.0);
        builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
        builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
        builder.write("Row 2, cell 1.");
        builder.insertCell();
        builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
        builder.write("Row 2, cell 2.");
        builder.endRow();
        builder.endTable();
        
        // Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
        Assert.assertEquals(0.0, table.getRows().get(0).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.AUTO, table.getRows().get(0).getRowFormat().getHeightRule());
        Assert.assertEquals(100.0, table.getRows().get(1).getRowFormat().getHeight());
        Assert.assertEquals(HeightRule.EXACTLY, table.getRows().get(1).getRowFormat().getHeightRule());
        Assert.assertEquals(TextOrientation.UPWARD, table.getRows().get(1).getCells().get(0).getCellFormat().getOrientation());
        Assert.assertEquals(TextOrientation.DOWNWARD, table.getRows().get(1).getCells().get(1).getCellFormat().getOrientation());
        
        doc.save(getArtifactsDir() + "DocumentBuilder.BuildTable.docx");