addImage
- addBackgroundImage
- addFooter
- addHeader
- addLineNumbering
- addPageBorders
- addProperties
- addSection
- createDocx
- createCharacterStyle
- createListStyle
- createParagraphStyle
- createTableStyle
- docxSettings
- embedFont
- importHeadersAndFooters
- importStyles
- modifyPageLayout
- removeFooters
- removeHeaders
- setBackgroundColor
- setDefaultFont
- setDocumentDefaultStyles
- setEncodeUTF8
- setLanguage
- setMarkAsFinal
- setRTL
- addBibliography
- addBookmark
- addBreak
- addChart
- addCitation
- addComment
- addCrossReference
- addDateAndHour
- addEndnote
- addExternalFile
- addFootnote
- addFormElement
- addHeading
- addImage
- addLink
- addList
- addMathEquation
- addMergeField
- addOLE
- addPageNumber
- addShape
- addSimpleField
- addSource
- addStructuredDocumentTag
- addTable
- addTableContents
- addText
- addTextBox
- addWordML
- embedHTML
- clearBlocks
- deleteTemplateBlock
- getTemplateVariables
- getTemplateVariablesType
- modifyInputFields
- modifyMergeFields
- processTemplate
- removeTemplateVariable
- replaceListVariable
- replacePlaceholderImage
- replaceTableVariable
- replaceVariableByExternalFile
- replaceVariableByHtml
- replaceVariableByText
- replaceVariableByWordFragment
- replaceVariableByWordML
- setTemplateSymbol
- tickCheckbox
addImage
BASIC / ADVANCED / PREMIUM
Inserts an image into the Word document.
Description
public void addImage(String src) throws Exception
public void addImage(String src, OptionsImage options) throws Exception
You may use this method to insert images (jpg, gif or png) into your Word document.
You may easily control:
- the embedding and positioning of the image within a complex paragraph.
- the size (if not explicitely given, Javadocx tries to read the width and height from the image headers).
- the dpi or dots per inch (by default they are taken from the image headers or set to 96 dpi).
- the scale (default 100%).
- the target: main document (default), headers or footers.
Together with some general formatting options.
If one wishes to insert an image within a complex paragraph or a table one should use this method in combination with the addText or the addTable method.
Parameters
options
Option | Type | Description |
---|---|---|
src | String | Path to the image that you want to insert into the Word document. |
borderColor | String | hexadecimal color: FF0000. |
borderStyle | String | Possible values are:
|
borderWidth | Integer | Given in emus (1cm = 360000 emus). |
caption | OptionsCaptionImage |
|
dpi | Integer | Dots per inch. |
float | String | (left, right, center) floating image. It only applies if textWrap is not inline (default value). |
height | Integer | Image height in pixels. |
horizontalOffset | Integer | Given in emus (1cm = 360000 emus). Only applies if the image is not floating. |
hyperlink | String | Image link. |
imageAlign | String | Image alignment: right, center... |
relativeToHorizontal | String | margin (default), page, column, character, leftMargin, rightMargin, insideMargin, outsideMargin. Not compatible with inline text wrapping. |
relativeToVertical | String | margin, page, line (default), paragraph, topMargin, bottomMargin, insideMargin, outsideMargin. Not compatible with inline text wrapping. |
scaling | Integer | % of size: 50, 100. |
spacingTop | Integer | Spacing top in pixels. |
spacingBottom | Integer | Spacing bottom in pixels. |
spacingLeft | Integer | Spacing left in pixels. |
spacingRight | Integer | Spacing right in pixels. |
target | String | document (default value), defaultHeader, firstHeader, evenHeader, defaultFooter, firstFooter, evenFooter, comment, endnote or footnote. One should use this parameter in conjuction with the "rawWordML" option to later insert the image in a header or footer. |
textWrap | Integer | Text wrap:
|
verticalOffset | Integer | Given in emus (1cm = 360000 emus). |
width | Integer | Image width in pixels. |