public class DocumentBuilder
extends java.lang.Object
To learn more, visit the Document Builder Overview documentation article.
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 getDocument() / setDocument(com.aspose.words.Document).
The DocumentBuilder has an internal cursor where the text will be inserted when you call write(java.lang.String), writeln(java.lang.String), M:Aspose.Words.DocumentBuilder.InsertBreak(Aspose.Words.BreakType) and other methods. You can navigate the DocumentBuilder cursor to a different location in a document using various MoveToXXX methods.
Use the getFont() property to specify character formatting that will apply to all text inserted from the current position in the document onwards.
Use the getParagraphFormat() property to specify paragraph formatting for the current and all paragraphs that will be inserted.
Use the getPageSetup() property to specify page and section properties for the current section and all section that will be inserted.
Use the getCellFormat() and getRowFormat() 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 and Description |
|---|
DocumentBuilder()
Initializes a new instance of this class.
|
DocumentBuilder(Document doc)
Initializes a new instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearCellAttrs() |
void |
clearRowAttrs() |
void |
clearRunAttrs() |
Row |
deleteRow(int tableIndex,
int rowIndex)
Deletes a row from a table.
|
BookmarkEnd |
endBookmark(java.lang.String bookmarkName)
Marks the current position in the document as a bookmark end.
|
BookmarkEnd |
endColumnBookmark(java.lang.String bookmarkName)
Marks the current position in the document as a column bookmark end.
|
EditableRangeEnd |
endEditableRange()
Marks the current position in the document as an editable range end.
|
EditableRangeEnd |
endEditableRange(EditableRangeStart start)
Marks the current position in the document as an editable range end.
|
Row |
endRow()
Ends a table row in the document.
|
Table |
endTable()
Ends a table in the document.
|
java.lang.Object |
fetchCellAttr(int key) |
java.lang.Object |
fetchInheritedCellAttr(int key) |
java.lang.Object |
fetchInheritedRowAttr(int key) |
java.lang.Object |
fetchInheritedRunAttr(int fontAttr) |
java.lang.Object |
fetchRowAttr(int key) |
boolean |
getBold()
True if the font is formatted as bold.
|
CellFormat |
getCellFormat()
Returns an object that represents current table cell formatting properties.
|
Node |
getCurrentNode()
Gets the node that is currently selected in this DocumentBuilder.
|
Paragraph |
getCurrentParagraph()
Gets the paragraph that is currently selected in this DocumentBuilder.
|
Section |
getCurrentSection()
Gets the section that is currently selected in this DocumentBuilder.
|
Story |
getCurrentStory()
Gets the story that is currently selected in this DocumentBuilder.
|
StructuredDocumentTag |
getCurrentStructuredDocumentTag()
Gets the structured document tag that is currently selected in this DocumentBuilder.
|
java.lang.Object |
getDirectCellAttr(int key) |
java.lang.Object |
getDirectRowAttr(int key) |
java.lang.Object |
getDirectRunAttr(int fontAttr) |
Document |
getDocument()
Gets the
getDocument() / setDocument(com.aspose.words.Document) object that this object is attached to. |
Font |
getFont()
Returns an object that represents current font formatting properties.
|
boolean |
getItalic()
True if the font is formatted as italic.
|
ListFormat |
getListFormat()
Returns an object that represents current list formatting properties.
|
PageSetup |
getPageSetup()
Returns an object that represents current page setup and section properties.
|
ParagraphFormat |
getParagraphFormat()
Returns an object that represents current paragraph formatting properties.
|
RowFormat |
getRowFormat()
Returns an object that represents current table row formatting properties.
|
int |
getUnderline()
Gets/sets underline type for the current font.
|
void |
insertBreak(int breakType) |
Cell |
insertCell()
Inserts a table cell into the document.
|
Shape |
insertChart(int chartType,
double width,
double height) |
Shape |
insertChart(int chartType,
int horzPos,
double left,
int vertPos,
double top,
double width,
double height,
int wrapType) |
FormField |
insertCheckBox(java.lang.String name,
boolean defaultValue,
boolean checkedValue,
int size)
Inserts a checkbox form field at the current position.
|
FormField |
insertCheckBox(java.lang.String name,
boolean checkedValue,
int size)
Inserts a checkbox form field at the current position.
|
FormField |
insertComboBox(java.lang.String name,
java.lang.String[] items,
int selectedIndex)
Inserts a combobox form field at the current position.
|
Node |
insertDocument(Document srcDoc,
int importFormatMode) |
Node |
insertDocument(Document srcDoc,
int importFormatMode,
ImportFormatOptions importFormatOptions) |
Field |
insertField(int fieldType,
boolean updateField) |
Field |
insertField(java.lang.String fieldCode)
|
Field |
insertField(java.lang.String fieldCode,
java.lang.String fieldValue)
Inserts a Word field into a document without updating the field result.
|
Footnote |
insertFootnote(int footnoteType,
java.lang.String footnoteText) |
Footnote |
insertFootnote(int footnoteType,
java.lang.String footnoteText,
java.lang.String referenceMark) |
Shape |
insertHorizontalRule()
Inserts a horizontal rule shape into the document.
|
void |
insertHtml(java.lang.String html)
Inserts an HTML string into the document.
|
void |
insertHtml(java.lang.String html,
boolean useBuilderFormatting)
Inserts an HTML string into the document.
|
void |
insertHtml(java.lang.String html,
int options) |
Field |
insertHyperlink(java.lang.String displayText,
java.lang.String urlOrBookmark,
boolean isBookmark)
Inserts a hyperlink into the document.
|
Shape |
insertImage(java.awt.image.BufferedImage image)
|
Shape |
insertImage(java.awt.image.BufferedImage image,
double width,
double height)
Inserts an inline image from a object into the document and scales it to the specified size.
|
Shape |
insertImage(java.awt.image.BufferedImage image,
int horzPos,
double left,
int vertPos,
double top,
double width,
double height,
int wrapType) |
Shape |
insertImage(byte[] imageBytes)
Inserts an image from a byte array into the document.
|
Shape |
insertImage(byte[] imageBytes,
double width,
double height)
Inserts an inline image from a byte array into the document and scales it to the specified size.
|
Shape |
insertImage(byte[] imageBytes,
int horzPos,
double left,
int vertPos,
double top,
double width,
double height,
int wrapType) |
Shape |
insertImage(java.io.InputStream stream) |
Shape |
insertImage(java.io.InputStream stream,
double width,
double height) |
Shape |
insertImage(java.io.InputStream stream,
int horzPos,
double left,
int vertPos,
double top,
double width,
double height,
int wrapType) |
Shape |
insertImage(java.lang.String fileName)
Inserts an image from a file or URL into the document.
|
Shape |
insertImage(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.
|
Shape |
insertImage(java.lang.String fileName,
int horzPos,
double left,
int vertPos,
double top,
double width,
double height,
int wrapType) |
void |
insertNode(Node node)
Inserts a node before the cursor.
|
Shape |
insertOleObject(java.io.InputStream stream,
java.lang.String progId,
boolean asIcon,
java.io.InputStream presentation) |
Shape |
insertOleObject(java.lang.String fileName,
boolean isLinked,
boolean asIcon,
java.io.InputStream presentation) |
Shape |
insertOleObject(java.lang.String fileName,
java.lang.String progId,
boolean isLinked,
boolean asIcon,
java.io.InputStream presentation) |
Shape |
insertOleObjectAsIcon(java.io.InputStream stream,
java.lang.String progId,
java.lang.String iconFile,
java.lang.String iconCaption) |
Shape |
insertOleObjectAsIcon(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.
|
Shape |
insertOleObjectAsIcon(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.
|
Shape |
insertOnlineVideo(java.lang.String videoUrl,
double width,
double height)
Inserts an online video object into the document and scales it to the specified size.
|
Shape |
insertOnlineVideo(java.lang.String videoUrl,
int horzPos,
double left,
int vertPos,
double top,
double width,
double height,
int wrapType) |
Shape |
insertOnlineVideo(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.
|
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) |
Paragraph |
insertParagraph()
Inserts a paragraph break into the document.
|
Shape |
insertShape(int shapeType,
double width,
double height) |
Shape |
insertShape(int shapeType,
int horzPos,
double left,
int vertPos,
double top,
double width,
double height,
int wrapType) |
Shape |
insertSignatureLine(SignatureLineOptions signatureLineOptions)
Inserts a signature line at the current position.
|
Shape |
insertSignatureLine(SignatureLineOptions signatureLineOptions,
int horzPos,
double left,
int vertPos,
double top,
int wrapType) |
void |
insertStyleSeparator()
Inserts style separator into the document.
|
Field |
insertTableOfContents(java.lang.String switches)
Inserts a TOC (table of contents) field into the document.
|
FormField |
insertTextInput(java.lang.String name,
int type,
java.lang.String format,
java.lang.String fieldValue,
int maxLength) |
boolean |
isAtEndOfParagraph()
Returns true if the cursor is at the end of the current paragraph.
|
boolean |
isAtEndOfStructuredDocumentTag()
Returns true if the cursor is at the end of a structured document tag.
|
boolean |
isAtStartOfParagraph()
Returns true if the cursor is at the beginning of the current paragraph (no text before the cursor).
|
void |
moveTo(Node node)
Moves the cursor to an inline node or to the end of a paragraph.
|
boolean |
moveToBookmark(java.lang.String bookmarkName)
Moves the cursor to a bookmark.
|
boolean |
moveToBookmark(java.lang.String bookmarkName,
boolean isStart,
boolean isAfter)
Moves the cursor to a bookmark with greater precision.
|
void |
moveToCell(int tableIndex,
int rowIndex,
int columnIndex,
int characterIndex)
Moves the cursor to a table cell in the current section.
|
void |
moveToDocumentEnd()
Moves the cursor to the end of the document.
|
void |
moveToDocumentStart()
Moves the cursor to the beginning of the document.
|
void |
moveToField(Field field,
boolean isAfter)
Moves the cursor to a field in the document.
|
void |
moveToHeaderFooter(int headerFooterType) |
boolean |
moveToMergeField(java.lang.String fieldName)
|
boolean |
moveToMergeField(java.lang.String fieldName,
boolean isAfter,
boolean isDeleteField)
Moves the merge field to the specified merge field.
|
void |
moveToParagraph(int paragraphIndex,
int characterIndex)
Moves the cursor to a paragraph in the current section.
|
void |
moveToSection(int sectionIndex)
Moves the cursor to the beginning of the body in a specified section.
|
void |
moveToStructuredDocumentTag(int structuredDocumentTagIndex,
int characterIndex)
Moves the cursor to a structured document tag in the current section.
|
void |
moveToStructuredDocumentTag(StructuredDocumentTag structuredDocumentTag,
int characterIndex)
Moves the cursor to the structured document tag.
|
void |
popFont()
Retrieves character formatting previously saved on the stack.
|
void |
pushFont()
Saves current character formatting onto the stack.
|
void |
removeRunAttr(int key) |
void |
resetToDefaultAttrs() |
void |
setBold(boolean value)
True if the font is formatted as bold.
|
void |
setCellAttr(int key,
java.lang.Object value) |
void |
setDocument(Document value)
Sets the
getDocument() / setDocument(com.aspose.words.Document) object that this object is attached to. |
void |
setItalic(boolean value)
True if the font is formatted as italic.
|
void |
setRowAttr(int key,
java.lang.Object value) |
void |
setRunAttr(int fontAttr,
java.lang.Object value) |
void |
setUnderline(int value)
Gets/sets underline type for the current font.
|
BookmarkStart |
startBookmark(java.lang.String bookmarkName)
Marks the current position in the document as a bookmark start.
|
BookmarkStart |
startColumnBookmark(java.lang.String bookmarkName)
Marks the current position in the document as a column bookmark start.
|
EditableRangeStart |
startEditableRange()
Marks the current position in the document as an editable range start.
|
Table |
startTable()
Starts a table in the document.
|
void |
write(java.lang.String text)
Inserts a string into the document at the current insert position.
|
void |
writeln()
Inserts a paragraph break into the document.
|
void |
writeln(java.lang.String text)
Inserts a string and a paragraph break into the document.
|
public DocumentBuilder()
throws java.lang.Exception
getDocument() / setDocument(com.aspose.words.Document) object.java.lang.Exceptionpublic DocumentBuilder(Document doc)
getDocument() / setDocument(com.aspose.words.Document) object. The cursor is positioned at the beginning of the document.doc - The Document object to attach to.public void moveToDocumentStart()
public void moveToDocumentEnd()
public void moveToSection(int sectionIndex)
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.
sectionIndex - The index of the section to move to.public void moveToHeaderFooter(int headerFooterType)
public boolean moveToMergeField(java.lang.String fieldName)
throws java.lang.Exception
Note that this method deletes the merge field from the document after moving the cursor.
fieldName - The case-insensitive name of the mail merge field.java.lang.Exceptionpublic boolean moveToMergeField(java.lang.String fieldName,
boolean isAfter,
boolean isDeleteField)
throws java.lang.Exception
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.java.lang.Exceptionpublic void moveToField(Field field, boolean isAfter) throws java.lang.Exception
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.java.lang.Exceptionpublic boolean moveToBookmark(java.lang.String bookmarkName)
throws java.lang.Exception
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.
bookmarkName - The name of the bookmark to move the cursor to.java.lang.Exceptionpublic boolean moveToBookmark(java.lang.String bookmarkName,
boolean isStart,
boolean isAfter)
throws java.lang.Exception
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.
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.java.lang.Exceptionpublic void moveToParagraph(int paragraphIndex,
int characterIndex)
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.
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.public void moveToStructuredDocumentTag(int structuredDocumentTagIndex,
int characterIndex)
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 structuredDocumentTagIndex specified the index of the structured document tag inside that header of that section.
When structuredDocumentTagIndex is greater than or equal to 0, it specifies an index from the beginning of the section with 0 being the first structured document tag. When structuredDocumentTagIndex is less than 0, it specified an index from the end of the section with -1 being the last structured document tag.
structuredDocumentTagIndex - The index of the structured document tag to move to.characterIndex - The index of the character inside the structured document tag. A negative value allows you to specify a position from the end of the structured document tag. Use -1 to move to the end of the structured document tag. If the structured document tag is at the block level, and you want to move the cursor to the end of its last paragraph, specify -2.public void moveToStructuredDocumentTag(StructuredDocumentTag structuredDocumentTag, int characterIndex)
structuredDocumentTag - The structured document tag to move to.characterIndex - The index of the character inside the structured document tag. A negative value allows you to specify a position from the end of the structured document tag. Use -1 to move to the end of the structured document tag. If the structured document tag is at the block level, and you want to move the cursor to the end of its last paragraph, specify -2.public void moveToCell(int tableIndex,
int rowIndex,
int columnIndex,
int characterIndex)
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.
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.public void moveTo(Node node)
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.
node - The node must be a paragraph or a direct child of a paragraph.public Row deleteRow(int tableIndex, int rowIndex)
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.
tableIndex - The index of the table.rowIndex - The index of the row in the table.public void write(java.lang.String text)
getFont() property is used.text - The string to insert into the document.public void writeln(java.lang.String text)
getFont() and getParagraphFormat() properties are used.text - The string to insert into the document.public void writeln()
Calls insertParagraph().
public Paragraph insertParagraph()
Current paragraph formatting specified by the getParagraphFormat() property is used.
Breaks the current paragraph in two. After inserting the paragraph, the cursor is placed at the beginning of the new paragraph.
getCurrentParagraph().public void insertStyleSeparator()
public void insertBreak(int breakType)
public Field insertTableOfContents(java.lang.String switches)
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 }. You can copy \o "1-3" \h \z 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.
switches - The TOC field switches.public Field insertField(int fieldType, boolean updateField) throws java.lang.Exception
java.lang.Exceptionpublic Field insertField(java.lang.String fieldCode) throws java.lang.Exception
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.
public Field insertField(java.lang.String fieldCode, java.lang.String fieldValue)
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.
public Field insertHyperlink(java.lang.String displayText, java.lang.String urlOrBookmark, boolean isBookmark)
Note that you need to specify font formatting for the hyperlink display text explicitly using the getFont() property.
This methods internally calls insertField(java.lang.String) to insert an MS Word HYPERLINK field into the document.
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.Field object that represents the inserted field.public FormField insertTextInput(java.lang.String name, int type, java.lang.String format, java.lang.String fieldValue, int maxLength) throws java.lang.Exception
java.lang.Exceptionpublic FormField insertCheckBox(java.lang.String name, boolean checkedValue, int size) throws java.lang.Exception
If you specify a name for the form field, then a bookmark is automatically created with the same name.
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.java.lang.Exceptionpublic FormField insertCheckBox(java.lang.String name, boolean defaultValue, boolean checkedValue, int size) throws java.lang.Exception
If you specify a name for the form field, then a bookmark is automatically created with the same name.
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.java.lang.Exceptionpublic FormField insertComboBox(java.lang.String name, java.lang.String[] items, int selectedIndex) throws java.lang.Exception
If you specify a name for the form field, then a bookmark is automatically created with the same name.
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.java.lang.Exceptionpublic Footnote insertFootnote(int footnoteType, java.lang.String footnoteText)
public Footnote insertFootnote(int footnoteType, java.lang.String footnoteText, java.lang.String referenceMark)
public Shape insertImage(java.awt.image.BufferedImage image) throws java.lang.Exception
image - The image to insert into the document.java.lang.Exceptionpublic Shape insertImage(java.lang.String fileName) throws java.lang.Exception
fileName - The file with the image. Can be any valid local or remote URI.java.lang.Exceptionpublic Shape insertImage(java.io.InputStream stream) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertImage(byte[] imageBytes) throws java.lang.Exception
imageBytes - The byte array that contains the image.java.lang.Exceptionpublic Shape insertImage(java.awt.image.BufferedImage image, double width, double height) throws java.lang.Exception
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.java.lang.Exceptionpublic Shape insertImage(java.lang.String fileName, double width, double height) throws java.lang.Exception
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.java.lang.Exceptionpublic Shape insertImage(java.io.InputStream stream, double width, double height) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertImage(byte[] imageBytes, double width, double height) throws java.lang.Exception
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.java.lang.Exceptionpublic 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
java.lang.Exceptionpublic Shape insertImage(java.lang.String fileName, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertImage(java.io.InputStream stream, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertImage(byte[] imageBytes, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertOleObject(java.io.InputStream stream, java.lang.String progId, boolean asIcon, java.io.InputStream presentation) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertOleObject(java.lang.String fileName, boolean isLinked, boolean asIcon, java.io.InputStream presentation) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertOleObject(java.lang.String fileName, java.lang.String progId, boolean isLinked, boolean asIcon, java.io.InputStream presentation) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertOleObjectAsIcon(java.lang.String fileName, boolean isLinked, java.lang.String iconFile, java.lang.String iconCaption) throws java.lang.Exception
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.java.lang.Exceptionpublic Shape insertOleObjectAsIcon(java.lang.String fileName, java.lang.String progId, boolean isLinked, java.lang.String iconFile, java.lang.String iconCaption) throws java.lang.Exception
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.java.lang.Exceptionpublic Shape insertOleObjectAsIcon(java.io.InputStream stream, java.lang.String progId, java.lang.String iconFile, java.lang.String iconCaption) throws java.lang.Exception
java.lang.Exceptionpublic void insertHtml(java.lang.String html)
throws java.lang.Exception
html - An HTML string to insert into the document.java.lang.Exceptionpublic void insertHtml(java.lang.String html,
boolean useBuilderFormatting)
throws java.lang.Exception
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.java.lang.Exceptionpublic void insertHtml(java.lang.String html,
int options)
throws java.lang.Exception
java.lang.Exceptionpublic Shape insertShape(int shapeType, double width, double height) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertShape(int shapeType, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertChart(int chartType, double width, double height) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertChart(int chartType, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertOnlineVideo(java.lang.String videoUrl, double width, double height) throws java.lang.Exception
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.java.lang.Exceptionpublic Shape insertOnlineVideo(java.lang.String videoUrl, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertOnlineVideo(java.lang.String videoUrl, java.lang.String videoEmbedCode, byte[] thumbnailImageBytes, double width, double height) throws java.lang.Exception
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.java.lang.Exceptionpublic 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
java.lang.Exceptionpublic Shape insertSignatureLine(SignatureLineOptions signatureLineOptions) throws java.lang.Exception
signatureLineOptions - The object that stores parameters of creating signature line.java.lang.Exceptionpublic Shape insertSignatureLine(SignatureLineOptions signatureLineOptions, int horzPos, double left, int vertPos, double top, int wrapType) throws java.lang.Exception
java.lang.Exceptionpublic Shape insertHorizontalRule() throws java.lang.Exception
java.lang.Exceptionpublic Cell insertCell()
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 getCellFormat() property to specify cell formatting.
public Table startTable()
The next method to call is insertCell().
This method starts a nested table when called inside a cell.
public Table endTable()
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.
public Row endRow()
Call EndRow to end a table row. If you call insertCell() immediately after that, then the table continues on a new row.
Use the getRowFormat() property to specify row formatting.
public BookmarkStart startBookmark(java.lang.String bookmarkName)
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.
bookmarkName - Name of the bookmark.public BookmarkEnd endBookmark(java.lang.String bookmarkName)
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.
bookmarkName - Name of the bookmark.public BookmarkStart startColumnBookmark(java.lang.String bookmarkName)
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.
bookmarkName - Name of the bookmark.public BookmarkEnd endColumnBookmark(java.lang.String bookmarkName)
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.
bookmarkName - Name of the bookmark.public EditableRangeStart startEditableRange()
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.
public EditableRangeEnd endEditableRange()
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.
public EditableRangeEnd endEditableRange(EditableRangeStart start)
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.
start - This editable range start.public Node insertDocument(Document srcDoc, int importFormatMode, ImportFormatOptions importFormatOptions)
public Document getDocument()
getDocument() / setDocument(com.aspose.words.Document) object that this object is attached to.getDocument() / setDocument(com.aspose.words.Document) object that this object is attached to.public void setDocument(Document value)
getDocument() / setDocument(com.aspose.words.Document) object that this object is attached to.value - The getDocument() / setDocument(com.aspose.words.Document) object that this object is attached to.public Font getFont()
Use Font to access and modify font formatting properties.
Specify font formatting before inserting text.
public boolean getBold()
boolean value.public void setBold(boolean value)
value - The corresponding boolean value.public boolean getItalic()
boolean value.public void setItalic(boolean value)
value - The corresponding boolean value.public int getUnderline()
int value. The returned value is one of Underline constants.public void setUnderline(int value)
value - The corresponding int value. The value must be one of Underline constants.public ParagraphFormat getParagraphFormat()
public ListFormat getListFormat()
public PageSetup getPageSetup()
public RowFormat getRowFormat()
public CellFormat getCellFormat()
public void pushFont()
public void popFont()
getFont(),
pushFont()public boolean isAtStartOfParagraph()
public boolean isAtEndOfParagraph()
public boolean isAtEndOfStructuredDocumentTag()
public void insertNode(Node node)
public Node getCurrentNode()
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 a paragraph or structured document tag, CurrentNode returns null.
getCurrentParagraph(),
getCurrentStructuredDocumentTag()public Paragraph getCurrentParagraph()
getCurrentNode()public StructuredDocumentTag getCurrentStructuredDocumentTag()
public Story getCurrentStory()
public Section getCurrentSection()
public java.lang.Object getDirectRunAttr(int fontAttr)
public java.lang.Object fetchInheritedRunAttr(int fontAttr)
public void setRunAttr(int fontAttr,
java.lang.Object value)
public void removeRunAttr(int key)
public void clearRunAttrs()
public java.lang.Object getDirectRowAttr(int key)
public java.lang.Object fetchRowAttr(int key)
public java.lang.Object fetchInheritedRowAttr(int key)
public void setRowAttr(int key,
java.lang.Object value)
public void clearRowAttrs()
public void resetToDefaultAttrs()
public java.lang.Object getDirectCellAttr(int key)
public java.lang.Object fetchCellAttr(int key)
public java.lang.Object fetchInheritedCellAttr(int key)
public void setCellAttr(int key,
java.lang.Object value)
public void clearCellAttrs()