ASPOSE home

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.
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.
RowFormatgetRowFormat()
           Returns an object that represents current table row formatting properties.
bytegetUnderline()
voidsetUnderline(byte 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.
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.
RowendRow()
           Ends a table row in the document.
TableendTable()
           Ends a table in the document.
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.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.
voidinsertBreak(int breakType)
           Inserts a break of the specified type into the document.
CellinsertCell()
           Inserts a table cell into the document.
FormFieldinsertCheckBox(java.lang.String name, boolean defaultValue, int size)
           Inserts a checkbox form field at the current position.
FormFieldinsertComboBox(java.lang.String name, java.lang.String[] items, int selectedIndex)
           Inserts a combobox form field at the current position.
FieldStartinsertField(java.lang.String fieldCode, java.lang.String fieldValue)
           Inserts a Word field into the document.
FieldStartinsertHyperlink(java.lang.String displayText, java.lang.String url, boolean isLocal)
           Inserts a hyperlink into the document.
ShapeinsertImage(byte[] imageBytes)
           Inserts an image from a byte array object into the document.
ShapeinsertImage(byte[] imageBytes, double width, double height)
           Inserts an image from a byte array object 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 a floating image from a byte array object at the specified position and size.
ShapeinsertImage(java.awt.image.BufferedImage image)
           Inserts an image from a java.awt.image.BufferedImage object into the document.
ShapeinsertImage(java.awt.image.BufferedImage image, double width, double height)
           Inserts an image from a java.awt.image.BufferedImage object into the document and scales it to the specified size.
ShapeinsertImage(java.awt.image.BufferedImage image, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
           Inserts a floating image from a java.awt.image.BufferedImage object at the specified position and size.
ShapeinsertImage(java.io.InputStream stream)
           Inserts an image from a stream into the document.
ShapeinsertImage(java.io.InputStream stream, double width, double height)
           Inserts an 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 a floating 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.
ShapeinsertImage(java.lang.String fileName, double width, double height)
           Inserts an 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 a floating 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.
ParagraphinsertParagraph()
           Inserts a paragraph break into the document.
voidinsertTableOfContents(java.lang.String switches)
           Inserts a TOC (table of contents) field into the document.
FormFieldinsertTextInput(java.lang.String name, int type, java.lang.String format, java.lang.String fieldValue, int maxLength)
           Inserts a text form field at the current position.
voidmoveTo(Node node)
           Moves the cursor to an inline node or to the end of a paragraph.
booleanmoveToBookmark(java.lang.String bookmarkName)
           Moves the cursor to a bookmark.
booleanmoveToBookmark(java.lang.String bookmarkName, boolean isStart, boolean isAfter)
           Moves the cursor to a bookmark with greater precision.
voidmoveToCell(int tableIndex, int rowIndex, int columnIndex, int characterIndex)
           Moves the cursor to a table cell in the current section.
voidmoveToDocumentEnd()
           Moves the cursor to the end of the document.
voidmoveToDocumentStart()
           Moves the cursor to the beginning of the document.
voidmoveToField(Field field, boolean isAfter)
           Moves the cursor to a field in the document.
voidmoveToHeaderFooter(int headerFooterType)
           Moves the cursor to the beginning of a header or footer in the current section.
booleanmoveToMergeField(java.lang.String fieldName)
           Moves the cursor to a position just beyond the specified merge field and removes the merge field.
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.
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.
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)
                throws java.lang.Exception
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

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.


getBold/setBold

public boolean getBold()

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

getItalic/setItalic

public boolean getItalic()

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

getUnderline/setUnderline

public byte getUnderline()

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

getParagraphFormat

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

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.

getRowFormat

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

getCellFormat

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

isAtStartOfParagraph

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

isAtEndOfParagraph

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

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

getCurrentStory

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

getCurrentSection

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

Method Detail

moveToDocumentStart

public void moveToDocumentStart()
                        throws java.lang.Exception
Moves the cursor to the beginning of the document.

moveToDocumentEnd

public void moveToDocumentEnd()
                      throws java.lang.Exception
Moves the cursor to the end of the document.

moveToSection

public void moveToSection(int sectionIndex)
                  throws java.lang.Exception
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.

moveToHeaderFooter

public void moveToHeaderFooter(int headerFooterType)
                       throws java.lang.Exception
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 moving cursor to a merge field deletes the merge field from the document.

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

Parameters:
fieldName - The name of the mail merge field you want to move the cursor to.
Returns:
True if the merge field was found; false otherwise.

moveToField

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

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.

moveToParagraph

public void moveToParagraph(int paragraphIndex, int characterIndex)
                    throws java.lang.Exception
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.

moveToCell

public void moveToCell(int tableIndex, int rowIndex, int columnIndex, int characterIndex)
               throws java.lang.Exception
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.

moveTo

public void moveTo(Node node)
           throws java.lang.Exception
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.

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

deleteRow

public Row deleteRow(int tableIndex, int rowIndex)
             throws java.lang.Exception, org.jaxen.JaxenException
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.

write

public void write(java.lang.String text)
          throws java.lang.Exception
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(java.lang.String text)
            throws java.lang.Exception
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.

writeln

public void writeln()
            throws java.lang.Exception
Inserts a paragraph break into the document.

Calls insertParagraph().


insertParagraph

public Paragraph insertParagraph()
                         throws java.lang.Exception
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.

insertBreak

public void insertBreak(int breakType)
                throws java.lang.Exception
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.

insertTableOfContents

public void insertTableOfContents(java.lang.String switches)
                          throws java.lang.Exception
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.

insertField

public FieldStart insertField(java.lang.String fieldCode, java.lang.String fieldValue)
                      throws java.lang.Exception
Inserts a Word field into the document.

Fields in MS 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 MS Word using the keyboard shortcut Alt+F9. Field codes appear between curly braces ( { } ).

To create fields using insertField(java.lang.String, java.lang.String), you need to specify a field type, field code and field value. If you are not sure about particular field code syntax, create the field in MS Word first and switch to see its field code.

Parameters:
fieldCode - Field code to insert (without curly braces).
fieldValue - Field value to insert. Pass null for fields that do not have a value.
Returns:
A FieldStart node that represents the beginning of the inserted field.

insertHyperlink

public FieldStart insertHyperlink(java.lang.String displayText, java.lang.String url, boolean isLocal)
                          throws java.lang.Exception
Inserts a hyperlink into the document.

This methods internally calls insertField(java.lang.String, java.lang.String) to insert an MS Word HYPERLINK field into the document. The HYPERLINK field is created by this method in the following format:

HYPERLINK \l "bookmarkName"

HYPERLINK "http://www.mydomain.com/myurl"

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

Parameters:
displayText - Text of the link to be displayed in the document.
url - 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.
isLocal - True if the url is a name of a bookmark inside the document.
Returns:
A FieldStart node that represents the beginning of the inserted field.

insertTextInput

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

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

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

insertCheckBox

public FormField insertCheckBox(java.lang.String name, boolean defaultValue, 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 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 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.

insertImage

public Shape insertImage(byte[] imageBytes)
                 throws java.lang.Exception
Inserts an image from a byte array object into the document.

The image is inserted inline and at 100% scale.

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

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

insertImage

public Shape insertImage(java.awt.image.BufferedImage image)
                 throws java.lang.Exception
Inserts an image from a java.awt.image.BufferedImage object into the document.

The image is inserted inline and at 100% scale.

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

Note: The image inserted in PNG format with default javax.imageio.ImageWriter settings. If you want to insert an BufferedImage in another format or with another settings, you should save the image into a byte array and use insertImage(byte[]) for image inserting.

Parameters:
image - The image to insert into the document.
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.

This overload is provided because it adds useful functionality of automatically downloading the image before inserting into the document if you specify a remote URI.

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:
fileName - The file with the image. Can be any valid URI.
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(byte[] imageBytes, double width, double height)
                 throws java.lang.Exception
Inserts an image from a byte array object into the document and scales it to the specified size.
The image node that was just inserted.

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.
width - The width of the image in points. Can be a negative value to request 100% scale.
height - The height if the image in points. Can be a negative value to request 100% scale.
Returns:
The image node that was just inserted.

insertImage

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

The image is inserted inline.

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

Note: The image inserted in PNG format with default javax.imageio.ImageWriter settings. If you want to insert an BufferedImage in another format or with another settings, you should save the image into a byte array and use insertImage(byte[]) for image inserting.

Parameters:
image - The image to insert into the document.
width - The width of the image in points. Can be a negative value to request 100% scale.
height - The height if the image in points. Can be a negative value to request 100% scale.
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 image from a file or URL into the document and scales it to the specified size.

The image is inserted inline.

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 value to request 100% scale.
height - The height if the image in points. Can be a negative value to request 100% scale.
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 image from a stream into the document and scales it to the specified size.

The image is inserted inline.

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 value to request 100% scale.
height - The height if the image in points. Can be a negative 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 a floating image from a byte array object at the specified position and size.

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

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 value to request 100% scale.
height - The height if the image in points. Can be a negative 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.awt.image.BufferedImage image, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                 throws java.lang.Exception
Inserts a floating image from a java.awt.image.BufferedImage object at the specified position and size.

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

Note: The image inserted in PNG format with default javax.imageio.ImageWriter settings. If you want to insert an BufferedImage in another format or with another settings, you should save the image into a byte array and use insertImage(byte[]) for image inserting.

Parameters:
image - The image to insert into the document.
horzPos - A RelativeHorizontalPosition value. Specifies where the distance to the image is measured from.
left - Distance in points from the origin to the left side of the image.
vertPos - A RelativeVerticalPosition value. Specifies where the distance to the image measured from.
top - Distance in points from the origin to the top side of the image.
width - The width of the image in points. Can be a negative value to request 100% scale.
height - The height if the image in points. Can be a negative 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, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                 throws java.lang.Exception
Inserts a floating 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 value to request 100% scale.
height - The height if the image in points. Can be a negative 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, int horzPos, double left, int vertPos, double top, double width, double height, int wrapType)
                 throws java.lang.Exception
Inserts a floating 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 value to request 100% scale.
height - The height if the image in points. Can be a negative 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.

insertCell

public Cell insertCell()
               throws java.lang.Exception
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.

startTable

public Table startTable()
                throws java.lang.Exception
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.

endTable

public Table endTable()
              throws java.lang.Exception
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.

endRow

public Row endRow()
          throws java.lang.Exception
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.

startBookmark

public BookmarkStart startBookmark(java.lang.String bookmarkName)
                           throws java.lang.Exception
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.

endBookmark

public BookmarkEnd endBookmark(java.lang.String bookmarkName)
                       throws java.lang.Exception
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.

pushFont

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

popFont

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

insertNode

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

clearCellAttrs

public void clearCellAttrs()
Reserved for internal use.

setCellAttr

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

fetchInheritedCellAttr

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

getDirectCellAttr

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

clearRowAttrs

public void clearRowAttrs()
Reserved for internal use.

setRowAttr

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

fetchInheritedRowAttr

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

getDirectRowAttr

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

clearRunAttrs

public void clearRunAttrs()
Reserved for internal use.

setRunAttr

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

fetchInheritedRunAttr

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

getDirectRunAttr

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

See Also:
          Wiki - the home page for the Aspose.Words Product Documentation that includes Programmer's Guide, Knowledge Base and other articles.
          Aspose.Words Support Forum - our preferred method of support.
          Aspose.Words Team - contact Aspose.Words Team.


ASPOSE home