com.aspose.words
Class DocumentBuilder

java.lang.Object
    extended by 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.


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()
voidsetBold(boolean value)
           True if the font is formatted as bold.
Aspose.Words.Tables.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()
voidsetDocument(Document value)
           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()
voidsetItalic(boolean value)
           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.
Aspose.Words.Tables.RowFormatgetRowFormat()
           Returns an object that represents current table row formatting properties.
intgetUnderline()
voidsetUnderline(int value)
           Gets/sets underline type for the current font. The value of the property is Underline integer constant.
 
Method Summary
voidclearCellAttrs()
          Reserved for internal use.
voidclearRowAttrs()
          Reserved for internal use.
voidclearRunAttrs()
          Reserved for internal use.
Aspose.Words.Tables.RowdeleteRow(int tableIndex, int rowIndex)
           Deletes a row from a table.
BookmarkEndendBookmark(java.lang.String bookmarkName)
           Marks the current position in the document as a bookmark end.
EditableRangeEndendEditableRange()
           Marks the current position in the document as an editable range end.
EditableRangeEndendEditableRange(EditableRangeStart start)
           Marks the current position in the document as an editable range end.
Aspose.Words.Tables.RowendRow()
           Ends a table row in the document.
Aspose.Words.Tables.TableendTable()
           Ends a table in the document.
java.lang.ObjectfetchCellAttr(int key)
          Reserved for internal use.
java.lang.ObjectfetchInheritedCellAttr(int key)
          Reserved for internal use.
java.lang.ObjectfetchInheritedRowAttr(int key)
          Reserved for internal use.
java.lang.ObjectfetchInheritedRunAttr(int fontAttr)
          Reserved for internal use.
java.lang.ObjectfetchRowAttr(int key)
          Reserved for internal use.
java.lang.ObjectgetDirectCellAttr(int key)
          Reserved for internal use.
java.lang.ObjectgetDirectRowAttr(int key)
          Reserved for internal use.
java.lang.ObjectgetDirectRunAttr(int fontAttr)
          Reserved for internal use.
intgetDirectRunAttrsCount()
          Reserved for internal use.
voidinsertBreak(int breakType)
           Inserts a break of the specified type into the document.
Aspose.Words.Tables.CellinsertCell()
           Inserts a table cell into the document.
Aspose.Words.Fields.FormFieldinsertCheckBox(java.lang.String name, boolean defaultValue, boolean checkedValue, int size)
           Inserts a checkbox form field at the current position.
Aspose.Words.Fields.FormFieldinsertCheckBox(java.lang.String name, boolean checkedValue, int size)
           Inserts a checkbox form field at the current position.
Aspose.Words.Fields.FormFieldinsertComboBox(java.lang.String name, java.lang.String[] items, int selectedIndex)
           Inserts a combobox form field at the current position.
NodeinsertDocument(Document srcDoc, int importFormatMode)
           Inserts content of the document into the current position of DocumentBuilder's cursor.
Aspose.Words.Fields.FieldinsertField(java.lang.String fieldCode)
           Inserts a Word field into a document and updates the field result.
Aspose.Words.Fields.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.
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.
Aspose.Words.Fields.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.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.
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.
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.
Aspose.Words.Fields.FieldinsertTableOfContents(java.lang.String switches)
           Inserts a TOC (table of contents) field into the document.
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.
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.
voidremoveRunAttr(int key)
          Reserved for internal use.
voidresetToDefaultAttrs()
          Reserved for internal use.
voidsetCellAttr(int key, java.lang.Object value)
          Reserved for internal use.
voidsetRowAttr(int key, java.lang.Object value)
          Reserved for internal use.
voidsetRunAttr(int fontAttr, java.lang.Object value)
          Reserved for internal use.
BookmarkStartstartBookmark(java.lang.String bookmarkName)
           Marks the current position in the document as a bookmark start.
EditableRangeStartstartEditableRange()
           Marks the current position in the document as an editable range start.
Aspose.Words.Tables.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.

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.

Property Getters/Setters Detail

getBold/setBold

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

getCellFormat

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

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.

See Also:
CurrentParagraph

getCurrentParagraph

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

getCurrentSection

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

getCurrentStory

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

getDocument/setDocument

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

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.


isAtEndOfParagraph

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

isAtStartOfParagraph

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

getItalic/setItalic

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

getListFormat

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

getPageSetup

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

getParagraphFormat

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

getRowFormat

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

getUnderline/setUnderline

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

Method Detail

clearCellAttrs

public void clearCellAttrs()
Reserved for internal use.

clearRowAttrs

public void clearRowAttrs()
Reserved for internal use.

clearRunAttrs

public void clearRunAttrs()
Reserved for internal use.

deleteRow

public Aspose.Words.Tables.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.

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.

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.

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.

endRow

public Aspose.Words.Tables.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.

endTable

public Aspose.Words.Tables.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.

fetchCellAttr

public java.lang.Object fetchCellAttr(int key)
Reserved for internal use.

fetchInheritedCellAttr

public java.lang.Object fetchInheritedCellAttr(int key)
Reserved for internal use.

fetchInheritedRowAttr

public java.lang.Object fetchInheritedRowAttr(int key)
Reserved for internal use.

fetchInheritedRunAttr

public java.lang.Object fetchInheritedRunAttr(int fontAttr)
Reserved for internal use.

fetchRowAttr

public java.lang.Object fetchRowAttr(int key)
Reserved for internal use.

getDirectCellAttr

public java.lang.Object getDirectCellAttr(int key)
Reserved for internal use.

getDirectRowAttr

public java.lang.Object getDirectRowAttr(int key)
Reserved for internal use.

getDirectRunAttr

public java.lang.Object getDirectRunAttr(int fontAttr)
Reserved for internal use.

getDirectRunAttrsCount

public int getDirectRunAttrsCount()
Reserved for internal use.

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.

insertCell

public Aspose.Words.Tables.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.

insertCheckBox

public Aspose.Words.Fields.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.
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.

insertCheckBox

public Aspose.Words.Fields.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.
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.

insertComboBox

public Aspose.Words.Fields.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.
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.

insertDocument

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

insertField

public Aspose.Words.Fields.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 Aspose.Words.Fields.Field object that represents the inserted field.
See Also:
Aspose.Words.Fields.Field

insertField

public Aspose.Words.Fields.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 #Error Cref: M:Aspose.Words.Fields.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 Aspose.Words.Fields.Field object that represents the inserted field.
See Also:
Aspose.Words.Fields.Field

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.

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.

insertHtml

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

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

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

insertHtml

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

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

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

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

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

insertHyperlink

public Aspose.Words.Fields.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 Aspose.Words.Fields.Field object that represents the inserted field.

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.

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.

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.

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.

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.

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.

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.

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.

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.

insertNode

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

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.

insertOnlineVideo

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

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

Insertion of online video from the following resources is supported:

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

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

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

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

insertOnlineVideo

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

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

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

insertOnlineVideo

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

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

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

insertParagraph

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

Current paragraph formatting specified by the ParagraphFormat property is used.

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

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

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.

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.

insertTableOfContents

public Aspose.Words.Fields.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.

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.

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.

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.

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.

moveToCell

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

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

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

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

moveToDocumentEnd

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

moveToDocumentStart

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

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.

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.

moveToMergeField

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

moveToParagraph

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

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

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

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

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.

popFont

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

pushFont

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

removeRunAttr

public void removeRunAttr(int key)
Reserved for internal use.

resetToDefaultAttrs

public void resetToDefaultAttrs()
Reserved for internal use.

setCellAttr

public void setCellAttr(int key, java.lang.Object value)
Reserved for internal use.

setRowAttr

public void setRowAttr(int key, java.lang.Object value)
Reserved for internal use.

setRunAttr

public void setRunAttr(int fontAttr, java.lang.Object value)
Reserved for internal use.

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.

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.

startTable

public Aspose.Words.Tables.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.

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.

writeln

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

Calls insertParagraph().


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.

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.