- Image
This class represents an image in a paragraph.
It is used to embed image data in BASE64 encoding.
- Meta
This class represents the metadata of a document.
It is used to set descriptive information about the document.
- CommonStyles
This class contains common styles of a document.
It is used to manage the named styles that are used in the document.
- FontFaceDeclarations
This class contains all font face declarations of a document.
It is used to manage the fonts that are used in the document.
- TextBody
This class represents the content of a text document.
- TextDocument
This class represents a text document in OpenDocument format.
- BulletListLevelStyle
This class represents a list style where list items are preceded by bullets.
- FontFace
This class represents a font face declaration.
It is used to describe the characteristics of a font which is used in the document. The unique name of a font can be used inside styles to select a font face declaration.
- ListStyle
This class represents a list style.
List styles are used to specify the formatting of a list and its items. A list style contains a set of style elements for each list level (@see ListLevelStyle). If a list style is applied to a list but does not contain a list level specification for a specific level, the list level style of the next lower level is used.
- Style
This class represents a style.
It is used to specify the formatting of a document or a portion of a document. The unique name of a style can be used to apply a formatting to elements.
- TabStop
This class represents a tab stop.
Tab stops are used to align text in a paragraph. To become effective they must be set to the style of the respective paragraph.
- Heading ⇐
Paragraph
This class represents a heading in a document.
It is used to structure a document into multiple sections. A chapter or section begins with a heading and extends to the next heading at the same or higher level.
- Hyperlink
This class represents a hyperlink in a paragraph.
- List
This class represents a list and may contain any number list items.
- ListItem
This class represents an item in a list.
- Paragraph
This class represents a paragraph.
This class represents an image in a paragraph.
It is used to embed image data in BASE64 encoding.
Since: 0.3.0
- Image
new Image(path)
.setAnchorType(anchorType)
⇒Image
.getAnchorType()
⇒AnchorType
.setHeight(height)
⇒Image
.getHeight()
⇒number
|undefined
.getPath()
⇒string
.setSize(width, height)
⇒Image
.setWidth(width)
⇒Image
.getWidth()
⇒number
|undefined
Creates an image
- path
string
Path to the image file that should be embedded
Example
const image = new Image('/home/homer/myself.png');
image.setAnchorType(anchorType)
⇒ Image
The setAnchorType()
method sets the anchor type setting of this image.
- anchorType
AnchorType
The anchor type setting
Return value
Image
- The Image
object
Example
const image = new Image('/home/homer/myself.png');
image.setAnchorType(AnchorType.AsChar);
Since: 0.9.0
The getAnchorType()
method returns the anchor type setting of this image.
Return value
AnchorType
- The anchor type setting
Example
const image = new Image('/home/homer/myself.png');
image.getAnchorType(); // AnchorType.Paragraph
image.setAnchorType(AnchorType.AsChar);
image.getAnchorType(); // AnchorType.AsChar
Since: 0.9.0
image.setHeight(height)
⇒ Image
The setHeight
method sets the target height of the image in millimeter.
If the provided value is too small, the height will be set to the minimal size 1
.
- height
number
The target height of the image in millimeter
Return value
Image
- The Image
object
Example
const image = new Image('/home/homer/myself.png');
image.setHeight(42); // 42
image.setHeight(-23); // 1
Since: 0.9.0
The getHeight()
method returns the target height of the image or undefined
if no height was set.
Return value
number
| undefined
- The target height of the image in millimeter or undefined
if no height was set
Example
const image = new Image('/home/homer/myself.png');
image.getHeight(); // undefined
image.setHeight(42);
image.getHeight(); // 42
Since: 0.9.0
The getPath()
method returns the path to the image file that should be embedded.
Return value
string
- The path to the image file
Example
const image = new Image('/home/homer/myself.png');
image.getPath(); // '/home/homer/myself.png'
Since: 0.7.0
image.setSize(width, height)
⇒ Image
The setSize()
method sets the target width and height of the image.
If any provided value is too small, it will be set to the minimal size 1
.
- width
number
The target width of the image in millimeter - height
number
The target height of the image in millimeter
Return value
Image
- The Image
object
Example
const image = new Image('/home/homer/myself.png');
image.setSize(42, 23); // w:42, h:32
image.setWidth(42, -23); // w:42, h:1
Since: 0.9.0
image.setWidth(width)
⇒ Image
The setWidth
method sets the target width of the image in millimeter.
If the provided value is too small, the width will be set to the minimal size 1
.
- width
number
The target width of the image in millimeter
Return value
Image
- The Image
object
Example
const image = new Image('/home/homer/myself.png');
image.setWidth(42); // 42
image.setWidth(-23); // 1
Since: 0.9.0
The getWidth()
method returns the target width of the image or undefined
if no width was set.
Return value
number
| undefined
- The target width of the image in millimeter or undefined
if no width was set
Example
const image = new Image('/home/homer/myself.png');
image.getWidth(); // undefined
image.setWidth(42);
image.getWidth(); // 42
Since: 0.9.0
This class represents the metadata of a document.
It is used to set descriptive information about the document.
Since: 0.6.0
- Meta
new Meta()
.setCreator(creator)
⇒Meta
.getCreator()
⇒string
|undefined
.getCreationDate()
⇒Date
.setDate(date)
⇒Meta
.getDate()
⇒Date
|undefined
.setDescription(description)
⇒Meta
.getDescription()
⇒string
|undefined
.getEditingCycles()
⇒number
.getGenerator()
⇒string
.setInitialCreator(initialCreator)
⇒Meta
.getInitialCreator()
⇒string
|undefined
.addKeyword(keyword)
⇒Meta
.getKeywords()
⇒Array.<string>
.removeKeyword(keyword)
⇒Meta
.clearKeywords()
⇒Meta
.setLanguage(language)
⇒Meta
.getLanguage()
⇒string
|undefined
.setPrintDate(printDate)
⇒Meta
.getPrintDate()
⇒Date
|undefined
.setPrintedBy(printedBy)
⇒Meta
.getPrintedBy()
⇒string
|undefined
.setSubject(subject)
⇒Meta
.getSubject()
⇒string
|undefined
.setTitle(title)
⇒Meta
.getTitle()
⇒string
|undefined
Creates a Meta
instance that represents the metadata of a document.
Initializes the creation date with the current time stamp and sets the username of the currently effective user as initial creator.
Example
const meta = new Meta();
meta.setCreator(creator)
⇒ Meta
The setCreator()
method sets the name of the person who last modified the document.
- creator
string
|undefined
The name of the person who last modified a document orundefined
to unset the creator
Return value
Meta
- The Meta
object
Example
const meta = new Meta();
meta.setCreator('Lisa Simpson'); // 'Lisa Simpson'
meta.setCreator(undefined); // undefined
Since: 0.6.0
The getCreator()
method returns the name of the person who last modified the document.
Return value
string
| undefined
- The name of the person who last modified the document
or undefined
if the creator is not set
Example
const meta = new Meta();
meta.getCreator(); // undefined
meta.setCreator('Lisa Simpson');
meta.getCreator(); // 'Lisa Simpson'
Since: 0.6.0
The getCreationDate()
method returns the UTC timestamp specifying the date and time when a document was created.
The creation date is initialized with the UTC timestamp of the moment the Meta
instance was created.
Return value
Date
- A Date
instance specifying the date and time when a document was created
Example
const meta = new Meta(); // 2020-04-01 12:00:00
meta.getCreationDate(); // 1585742400000
Since: 0.6.0
meta.setDate(date)
⇒ Meta
The setDate()
method sets the date and time when the document was last modified.
- date
Date
|undefined
ADate
instance specifying the date and time when the document was last modified orundefined
to unset the date
Return value
Meta
- The Meta
object
Example
const meta = new Meta();
meta.setDate(new Date()); // 2020-07-23 13:37:00
Since: 0.6.0
The getDate()
method returns the date and time when the document was last modified.
Return value
Date
| undefined
- A Date
instance specifying the date and time when the document was last modified
or undefined
if the date is not set
Example
const meta = new Meta();
meta.getDate(); // undefined
meta.setDate(new Date()); // 2020-07-23 13:37:00
meta.getDate(); // 1595511420000
Since: 0.6.0
meta.setDescription(description)
⇒ Meta
The setDescription()
method sets the description of the document.
- description
string
|undefined
The description of the document orundefined
to unset the description
Return value
Meta
- The Meta
object
Example
const meta = new Meta();
meta.setDescription('Memoirs of the yellow man wearing blue trousers');
Since: 0.6.0
The getDescription()
method returns the description of the document.
Return value
string
| undefined
- The description of the document or undefined
if the description is not set
Example
const meta = new Meta();
meta.getDescription(); // undefined
meta.setDescription('Memoirs of the yellow man wearing blue trousers');
meta.getDescription(); // 'Memoirs of the yellow man wearing blue trousers'
Since: 0.6.0
The getEditingCycles()
method returns the number of times the document has been edited.
When the Meta
instance is being created, the value is set to 1
.
Return value
number
- The number of times a document has been edited
Example
const meta = new Meta();
meta.getEditingCycles(); // 1
Since: 0.6.0
The getGenerator()
method returns a string that identifies simple-odf as the OpenDocument producer
that was used to create the document.
The string matches the definition for user-agents as defined in RFC2616.
Return value
string
- A string that identifies simple-odf as the OpenDocument producer of this document
Example
const meta = new Meta();
meta.getGenerator(); // simple-odf/0.6.0
Since: 0.6.0
meta.setInitialCreator(initialCreator)
⇒ Meta
The setInitialCreator()
method sets the name of the initial creator of the document.
The initial creator is initialized with the username of the currently effective user.
- initialCreator
string
|undefined
The name of the initial creator of the document orundefined
to unset the initial creator
Return value
Meta
- The Meta
object
Example
const meta = new Meta(); // 'Homer Simpson'
meta.setInitialCreator('Bart Simpson'); // 'Bart Simpson'
meta.setInitialCreator(undefined); // undefined
Since: 0.6.0
The getInitialCreator()
method returns the name of the initial creator of the document.
Return value
string
| undefined
- The name of the initial creator of the document
or undefined
if the initial creator is not set
Example
const meta = new Meta();
meta.getInitialCreator(); // 'Homer Simpson'
meta.setInitialCreator('Bart Simpson');
meta.getInitialCreator(); // 'Bart Simpson'
Since: 0.6.0
meta.addKeyword(keyword)
⇒ Meta
The addKeyword()
method adds a keyword pertaining to a document to the end of the keyword list.
If the given string includes comma characters, the string will be split and added as multiple key words.
- keyword
string
The keyword to add to the end of the keyword list
Return value
Meta
- The Meta
object
Example
const meta = new Meta(); // []
meta.addKeyword('memoirs'); // ['memoirs']
meta.addKeyword('Simpson,family,Springfield'); // ['memoirs', 'Simpson', 'family', 'Springfield']
Since: 0.6.0
The getKeywords()
method returns a new Array
object that contains the keywords of the document.
Return value
Array.<string>
- A new Array
object that contains the keywords of the document
Example
const meta = new Meta();
meta.getKeywords(); // []
meta.addKeyword('Simpson,Springfield');
meta.getKeywords(); // ['Simpson', 'Springfield']
Since: 0.6.0
meta.removeKeyword(keyword)
⇒ Meta
The removeKeyword()
method removes the specified keyword from the keyword list.
- keyword
string
The keyword to remove from the keyword list
Return value
Meta
- The Meta
object
Example
const meta = new Meta();
meta.addKeyword('Simpson,Springfield'); // ['Simpson', 'Springfield']
meta.removeKeyword('Simpson'); // ['Springfield']
Since: 0.6.0
meta.clearKeywords()
⇒ Meta
The clearKeywords()
method removes all elements from the keyword list.
Return value
Meta
- The Meta
object
Example
const meta = new Meta();
meta.addKeyword('Simpson,Springfield'); // ['Simpson', 'Springfield']
meta.clearKeywords(); // []
Since: 0.6.0
meta.setLanguage(language)
⇒ Meta
The setLanguage()
method sets default language of the document.
A language is a natural language identifier as defined by RFC5646.
If an illegal value is provided, the value will be ignored.
- language
string
|undefined
The default language of the document orundefined
to unset the default language
Return value
Meta
- The Meta
object
Example
const meta = new Meta(); // undefined
meta.setLanguage('en-US'); // 'en-US'
meta.setLanguage('illegal'); // 'en-US'
Since: 0.6.0
The getLanguage()
method returns the default language of the document.
Return value
string
| undefined
- The default language of the document
or undefined
if the default language is not set
Example
const meta = new Meta();
meta.getLanguage(); // undefined
meta.setLanguage('en-US');
meta.getLanguage(); // 'en-US'
Since: 0.6.0
meta.setPrintDate(printDate)
⇒ Meta
The setPrintDate()
method sets the date and time when the document was last printed.
- printDate
Date
|undefined
ADate
instance specifying the date and time when the document was last printed orundefined
to unset the print date
Return value
Meta
- The Meta
object
Example
const meta = new Meta();
meta.setPrintDate(new Date()); // 2020-07-23 13:37:00
Since: 0.6.0
The getPrintDate()
method returns the date and time when the document was last printed.
Return value
Date
| undefined
- A Date
instance specifying the date and time when the document was last printed
or undefined
if the print date is not set
Example
const meta = new Meta();
meta.getPrintDate(); // undefined
meta.setPrintDate(new Date()); // 2020-07-23 13:37:00
meta.getPrintDate(); // 1595511420000
Since: 0.6.0
meta.setPrintedBy(printedBy)
⇒ Meta
The setPrintedBy()
method sets the name of the last person who printed the document.
- printedBy
string
|undefined
The name of the last person who printed the document orundefined
to unset the name of the person
Return value
Meta
- The Meta
object
Example
const meta = new Meta();
meta.setPrintedBy('Marge Simpson'); // 'Marge Simpson'
meta.setPrintedBy(undefined); // undefined
Since: 0.6.0
The getPrintedBy()
method returns the name of the last person who printed the document.
Return value
string
| undefined
- The name of the last person who printed the document
or undefined
if the name of the person is not set
Example
const meta = new Meta();
meta.getPrintedBy(); // undefined
meta.setPrintedBy('Marge Simpson');
meta.getPrintedBy(); // 'Marge Simpson'
Since: 0.6.0
meta.setSubject(subject)
⇒ Meta
The setSubject()
method sets the subject of the document.
- subject
string
|undefined
The subject of the document orundefined
to unset the subject
Return value
Meta
- The Meta
object
Example
const meta = new Meta();
meta.setSubject('Simpsons'); // 'Simpsons'
meta.setSubject(undefined); // undefined
Since: 0.6.0
The getSubject()
method returns the subject of the document.
Return value
string
| undefined
- The subject of the document or undefined
if the subject is not set
Example
const meta = new Meta();
meta.getSubject(); // undefined
meta.setSubject('Simpsons');
meta.getSubject(); // 'Simpsons'
Since: 0.6.0
meta.setTitle(title)
⇒ Meta
The setTitle()
method sets the title of the document.
- title
string
|undefined
The title of the document orundefined
to unset the title
Return value
Meta
- The Meta
object
Example
const meta = new Meta();
meta.setTitle('Memoirs of Homer Simpson'); // 'Memoirs of Homer Simpson'
meta.setTitle(undefined); // undefined
Since: 0.6.0
The getTitle()
method returns the title of the document.
Return value
string
| undefined
- The title of the document or undefined
if the title is not set
Example
const meta = new Meta();
meta.getTitle(); // undefined
meta.setTitle('Memoirs of Homer Simpson');
meta.getTitle(); // 'Memoirs of Homer Simpson'
Since: 0.6.0
This class contains common styles of a document.
It is used to manage the named styles that are used in the document.
Since: 0.9.0
- CommonStyles
new CommonStyles()
.createListStyle(name)
⇒ListStyle
.createParagraphStyle(name)
⇒ParagraphStyle
.getName(displayName)
⇒string
|undefined
.getAll()
Creates a CommonStyles
instance that represents the common styles of a document.
Example
const commonStyles = new CommonStyles();
commonStyles.createListStyle(name)
⇒ ListStyle
The createListStyle()
method creates a new ListStyle
instance with the given name.
If a style with this name already exists, the existing style will be returned.
- name
string
The unique name for the style
Return value
ListStyle
- A new ListStyle
instance with the specified name or an existing style, if one with the specified name exists
Example
const commonStyles = new CommonStyles();
commonStyles.createListStyle('Contents');
Since: 0.11.0
The createParagraphStyle()
method creates a new ParagraphStyle
instance with the given name.
If a style with this name already exists, the existing style will be returned.
- name
string
The unique name for the style
Return value
ParagraphStyle
- A new ParagraphStyle
instance with the specified name
or an existing style, if one with the specified name exists
Example
const commonStyles = new CommonStyles();
commonStyles.createParagraphStyle('Summary');
Since: 0.9.0
The getName()
method returns the unique name of the style with the specified display name.
- displayName
string
The display name of the requested style
Return value
string
| undefined
- The unique name of the style with the specified display name
or undefined
if there is no style with this display name
Example
const commonStyles = new CommonStyles();
commonStyles.createParagraphStyle('Heading 1');
commonStyles.getName('UnknownStyle'); // undefined
commonStyles.getName('Heading 1'); // Heading_20_1
Since: 0.9.0
This class contains all font face declarations of a document.
It is used to manage the fonts that are used in the document.
Since: 0.8.0
- FontFaceDeclarations
.create(name, [fontFamily], [fontPitch])
⇒FontFace
.get(name)
⇒FontFace
|undefined
.getAll()
⇒Array.<FontFace>
.delete(name)
⇒Meta
fontFaceDeclarations.create(name, [fontFamily], [fontPitch])
⇒ FontFace
Creates a FontFace object with the given name. If a font with this name already exists, the existing font will be returned.
- name
string
The unique name for the font - [fontFamily]
string
The name of the font family - [fontPitch]
FontPitch
Indicator whether the font has a fixed or variable width
Return value
FontFace
- A new FontFace
object with the specified properties
or an existing font face, if one with the specified name exists
Example
const fontFaceDeclarations = new FontFaceDeclarations();
fontFaceDeclarations.create('FreeSans', 'FreeSans', FontPitch.Variable);
Since: 0.8.0
fontFaceDeclarations.get(name)
⇒ FontFace
| undefined
The get()
method returns a specified element from a Map object.
- name
string
The name of the requested font
Return value
FontFace
| undefined
- The FontFace
object associated with the specified name
or undefined
if there is no font with this name
Example
const fontFaceDeclarations = new FontFaceDeclarations();
fontFaceDeclarations.create('FreeSans');
fontFaceDeclarations.get('UnknownFont'); // undefined
fontFaceDeclarations.get('FreeSans'); // FreeSans font
Since: 0.8.0
fontFaceDeclarations.getAll()
⇒ Array.<FontFace>
The getAll()
method returns a new Array
object that contains the fonts of the document.
Return value
Array.<FontFace>
- A new Array
object that contains the fonts of the document
Example
const fontFaceDeclarations = new FontFaceDeclarations();
fontFaceDeclarations.create('FreeSans');
fontFaceDeclarations.create('Symbol');
fontFaceDeclarations.getAll(); // [FreeSans, Symbol]
Since: 0.8.0
fontFaceDeclarations.delete(name)
⇒ Meta
The delete()
method removes the specified font from the font face declarations.
- name
string
The name of the font to remove from the font face declarations
Return value
Meta
- The Meta
object
Example
var myMap = new Map();
const fontFaceDeclarations = new FontFaceDeclarations();
fontFaceDeclarations.create('FreeSans');
fontFaceDeclarations.create('Symbol');
fontFaceDeclarations.delete('FreeSans');
fontFaceDeclarations.get('FreeSans'); // undefined
Since: 0.8.0
This class represents the content of a text document.
Since: 0.7.0
textBody.addHeading([text], [level])
⇒ Heading
Adds a heading at the end of the document. If a text is given, this will be set as text content of the heading.
- [text]
string
The text content of the heading - [level]
number
= 1
The heading level; defaults to 1 if omitted
Return value
Heading
- The newly added heading
Since: 0.7.0
textBody.addList()
⇒ List
Adds an empty list at the end of the document.
Return value
List
- The newly added list
Example
new TextBody()
.addList();
Since: 0.7.0
textBody.addParagraph([text])
⇒ Paragraph
Adds a paragraph at the end of the document. If a text is given, this will be set as text content of the paragraph.
- [text]
string
The text content of the paragraph
Return value
Paragraph
- The newly added paragraph
Since: 0.7.0
This class represents a text document in OpenDocument format.
Since: 0.1.0
- TextDocument
new TextDocument()
.getBody()
⇒TextBody
.getCommonStyles()
⇒CommonStyles
.getFontFaceDeclarations()
⇒FontFaceDeclarations
.getMeta()
⇒Meta
.saveFlat(filePath)
⇒Promise.<void>
.toString()
⇒string
Creates a TextDocument
instance that represents a OpenDocument text document.
Example
const document = new TextDocument();
textDocument.getBody()
⇒ TextBody
The getBody()
method returns the content of the document.
Return value
TextBody
- A TextBody
object that holds the content of the document
Example
new TextDocument()
.getBody()
.addHeading('My first document');
Since: 0.7.0
textDocument.getCommonStyles()
⇒ CommonStyles
The getCommonStyles()
method returns the named styles of the document.
Return value
CommonStyles
- A CommonStyles
object that holds the named styles of the document
Example
new TextDocument()
.getCommonStyles()
.createParagraphStyle('Summary');
Since: 0.9.0
textDocument.getFontFaceDeclarations()
⇒ FontFaceDeclarations
The getFontFaceDeclarations()
method returns the font face declarations of the document.
Return value
FontFaceDeclarations
- An object holding the font faces of the document
Example
new TextDocument()
.getFontFaceDeclarations()
.create('FreeSans', 'FreeSans', FontPitch.Variable);
Since: 0.8.0
textDocument.getMeta()
⇒ Meta
The getMeta()
method returns the metadata of the document.
Return value
Meta
- An object holding the metadata of the document
Example
new TextDocument()
.getMeta()
.setCreator('Homer Simpson');
Since: 0.6.0
The saveFlat()
method converts the document into an XML string and stores it in flat open document xml format.
- filePath
string
The file path to write to
Example
new TextDocument()
.saveFlat('/home/homer/document.fodt');
Since: 0.1.0
Returns the string representation of this document in flat open document xml format.
Return value
string
- The string representation of this document
Since: 0.1.0
This class represents a list style where list items are preceded by bullets.
Since: 0.11.0
- BulletListLevelStyle
new BulletListLevelStyle(level)
.getBulletChar()
⇒string
.setBulletChar(bulletChar)
⇒BulletListLevelStyle
.getLevel()
⇒number
.getNumberPrefix()
⇒string
|undefined
.setNumberPrefix(prefix)
⇒BulletListLevelStyle
.getNumberSuffix()
⇒string
|undefined
.setNumberSuffix(suffix)
⇒BulletListLevelStyle
.getRelativeBulletSize()
⇒string
|undefined
.setRelativeBulletSize(relativeSize)
⇒BulletListLevelStyle
Creates a BulletListLevelStyle
instance that represents a list style where list items are preceded by bullets.
- level
number
The level of the list style, starting with1
Example
const style = new BulletListLevelStyle(3);
The getBulletChar()
method returns the character to use as the bullet.
Return value
string
- The character to use as the bullet
Example
const style = new BulletListLevelStyle(3);
style.getBulletChar(); // '\u2022'
style.setBulletChar('~');
style.getBulletChar(); // '~'
Since: 0.11.0
bulletListLevelStyle.setBulletChar(bulletChar)
⇒ BulletListLevelStyle
The setBulletChar()
method sets the character to use as the bullet.
If an illegal value is provided, the value will be ignored.
- bulletChar
string
The character to use as the bullet
Return value
BulletListLevelStyle
- The BulletListLevelStyle
object
Example
const style = new BulletListLevelStyle(3);
style.setBulletChar('~'); // '~'
style.setBulletChar(''); // '~'
Since: 0.11.0
The getLevel()
method returns the level of the list style.
Return value
number
- The level of the list style, starting with 1
Example
const style = new BulletListLevelStyle(3);
style.getLevel(); // 3
Since: 0.11.0
The getNumberPrefix()
method returns the character to display before a bullet.
Return value
string
| undefined
- The character to display before a bullet or undefined
if no prefix is set
Example
const style = new BulletListLevelStyle(3);
style.getNumberPrefix(); // undefined
style.setNumberPrefix('~');
style.getNumberPrefix(); // '~'
Since: 0.11.0
bulletListLevelStyle.setNumberPrefix(prefix)
⇒ BulletListLevelStyle
The setNumberPrefix()
method sets the character to display before a bullet.
- prefix
string
|undefined
The character to display before a bullet orundefined
to unset the prefix
Return value
BulletListLevelStyle
- The BulletListLevelStyle
object
Example
const style = new BulletListLevelStyle(3);
style.setNumberPrefix('~'); // '~'
style.setNumberPrefix(undefined); // undefined
Since: 0.11.0
The getNumberSuffix()
method returns the character to display after a bullet.
Return value
string
| undefined
- The character to display after a bullet or undefined
if no suffix is set
Example
const style = new BulletListLevelStyle(3);
style.getNumberSuffix(); // undefined
style.setNumberSuffix('~');
style.getNumberSuffix(); // '~'
Since: 0.11.0
bulletListLevelStyle.setNumberSuffix(suffix)
⇒ BulletListLevelStyle
The setNumberSuffix()
method sets the character to display after a bullet.
- suffix
string
|undefined
The character to display after a bullet orundefined
to unset the suffix
Return value
BulletListLevelStyle
- The BulletListLevelStyle
object
Example
const style = new BulletListLevelStyle(3);
style.setNumberSuffix('~'); // '~'
style.setNumberSuffix(undefined); // undefined
Since: 0.11.0
The getRelativeBulletSize()
method returns the percentage value for the bullet size relative to the font size of the paragraphs in the bullet list.
Return value
string
| undefined
- The percentage value for the bullet size or undefined
if no relative bullet size is set
Example
const style = new BulletListLevelStyle(3);
style.getRelativeBulletSize(); // undefined
style.setRelativeBulletSize('23%');
style.getRelativeBulletSize(); // '23%'
Since: 0.11.0
bulletListLevelStyle.setRelativeBulletSize(relativeSize)
⇒ BulletListLevelStyle
The setNumberSuffix()
method sets the percentage value for the bullet size relative to the font size of the paragraphs in the bullet list.
If an illegal value is provided, the value will be ignored.
- relativeSize
string
|undefined
The percentage value for the bullet size orundefined
to unset the bullet size
Return value
BulletListLevelStyle
- The BulletListLevelStyle
object
Example
const style = new BulletListLevelStyle(3);
style.setRelativeBulletSize('23%'); // '23%'
style.setRelativeBulletSize('42px'); // '23%'
style.setRelativeBulletSize(undefined); // undefined
Since: 0.11.0
This class represents a font face declaration.
It is used to describe the characteristics of a font which is used in the document. The unique name of a font can be used inside styles to select a font face declaration.
Since: 0.8.0
- FontFace
new FontFace(name, [fontFamily], [fontPitch])
.setCharset(fontCharset)
⇒FontFace
.getCharset()
⇒string
|undefined
.setFontFamily(fontFamily)
⇒FontFace
.getFontFamily()
⇒string
|undefined
.setFontFamilyGeneric(fontFamilyGeneric)
⇒FontFace
.getFontFamilyGeneric()
⇒string
|undefined
.setFontPitch(fontPitch)
⇒FontFace
.getFontPitch()
⇒string
|undefined
.getName()
⇒string
Creates a FontFace
instance that represents the characteristics of a font.
- name
string
The unique name for the font - [fontFamily]
string
The name of the font family - [fontPitch]
FontPitch
Indicator whether the font has a fixed or variable width
Example
const font = new FontFace('FreeSans', 'FreeSans', FontPitch.Variable);
const font = new FontFace('FreeSans', 'FreeSans');
const font = new FontFace('FreeSans');
fontFace.setCharset(fontCharset)
⇒ FontFace
The setCharset()
method sets whether the font defines glyphs according to the semantics of Unicode or not.
The value can be x-symbol
or a character encoding.
If an illegal value is provided, the value will be ignored.
- fontCharset
string
|undefined
The charset of the font orundefined
to unset the charset
Return value
FontFace
- The FontFace
object
Example
const font = new FontFace('OpenSymbol', 'OpenSymbol', FontPitch.Variable);
font.setCharset('x-symbol'); // 'x-symbol'
font.setCharset('23'); // 'x-symbol'
font.setCharset(undefined); // undefined
Since: 0.8.0
The getCharset()
method returns whether the font defines glyphs according to the semantics of Unicode or not.
Return value
string
| undefined
- The charset of the font or undefined
if the charset is not set
Example
const font = new FontFace('OpenSymbol', 'OpenSymbol', FontPitch.Variable);
font.getCharset(); // undefined
font.setCharset('x-symbol');
font.getCharset(); // 'x-symbol'
Since: 0.8.0
fontFace.setFontFamily(fontFamily)
⇒ FontFace
The setFontFamily()
method sets the font family which is to be used to render the text.
- fontFamily
string
|undefined
The font family of the font orundefined
to unset the font family
Return value
FontFace
- The FontFace
object
Example
const font = new FontFace('OpenSymbol');
font.setFontFamily('OpenSymbol'); // 'OpenSymbol'
font.setFontFamily(undefined); // undefined
Since: 0.8.0
The getFontFamily()
method returns the font family which is to be used to render the text.
Return value
string
| undefined
- The font family of the font or undefined
if the font family is not set
Example
const font = new FontFace('OpenSymbol');
font.setFontFamily('OpenSymbol'); // 'OpenSymbol'
font.setFontFamily(undefined); // undefined
Since: 0.8.0
fontFace.setFontFamilyGeneric(fontFamilyGeneric)
⇒ FontFace
The setFontFamilyGeneric()
method sets the generic font family name of the font.
- fontFamilyGeneric
FontFamilyGeneric
|undefined
The generic font family name orundefined
to unset the generic font family name
Return value
FontFace
- The FontFace
object
Example
const font = new FontFace('OpenSymbol');
font.setFontFamilyGeneric(FontFamilyGeneric.System); // 'system'
font.setFontFamilyGeneric(undefined); // undefined
Since: 0.8.0
The getFontFamilyGeneric()
method returns the generic font family name of the font.
Return value
string
| undefined
- The generic font family name of the font
or undefined
if the generic font family name is not set
Example
const font = new FontFace('OpenSymbol');
font.getFontFamilyGeneric(); // undefined
font.setFontFamilyGeneric(FontFamilyGeneric.System);
font.getFontFamilyGeneric(); // 'system'
Since: 0.8.0
fontFace.setFontPitch(fontPitch)
⇒ FontFace
The setFontPitch()
method sets whether the font has a fixed or variable width.
- fontPitch
FontPitch
|undefined
The pitch of the font orundefined
to unset the font pitch
Return value
FontFace
- The FontFace
object
Example
const font = new FontFace('OpenSymbol');
font.setFontPitch(FontPitch.Variable); // variable
font.setFontPitch(undefined); // undefined
Since: 0.8.0
The getFontPitch()
method returns whether the font has a fixed or variable width.
Return value
string
| undefined
- The pitch of the font or undefined
if the font pitch is not set
Example
const font = new FontFace('OpenSymbol');
font.getFontPitch(); // undefined
font.setFontPitch(FontPitch.Variable);
font.getFontPitch(); // variable
Since: 0.8.0
The getName()
method returns the unique name of the font.
Return value
string
- A string that identifies the font in this document
Example
const font = new FontFace('FreeSans');
font.getName(); // 'FreeSans'
Since: 0.8.0
This class represents a list style.
List styles are used to specify the formatting of a list and its items. A list style contains a set of style elements for each list level (@see ListLevelStyle). If a list style is applied to a list but does not contain a list level specification for a specific level, the list level style of the next lower level is used.
Since: 0.11.0
- ListStyle
new ListStyle(displayName)
.getConsecutiveNumbering()
⇒boolean
.setConsecutiveNumbering(consecutiveNumbering)
⇒ListStyle
.createBulletListLevelStyle(level)
⇒BulletListLevelStyle
.getListLevelStyle(level)
⇒BulletListLevelStyle
|undefined
.getListLevelStyles()
⇒Array.<BulletListLevelStyle>
.removeListLevelStyle(level)
⇒ListStyle
Creates a ListStyle
instance that represents the formatting of a list.
- displayName
string
The unique display name for the style
Example
const style = new ListStyle('Contents');
The getConsecutiveNumbering()
method returns whether the style uses consecutive numbering for all list levels or whether each list level restarts the numbering.
Return value
boolean
- true
if consecutive numbering is used for all list levels or false
if each list level restarts numbering
Example
const style = new ListStyle('Contents');
style.getConsecutiveNumbering(); // false
style.setConsecutiveNumbering(true);
style.getConsecutiveNumbering(); // true
Since: 0.11.0
listStyle.setConsecutiveNumbering(consecutiveNumbering)
⇒ ListStyle
The setConsecutiveNumbering()
method sets returns whether the style uses consecutive numbering for all list levels or whether each list level restarts the numbering.
- consecutiveNumbering
boolean
true
if consecutive numbering is used for all list levels orfalse
if each list level restarts numbering
Return value
ListStyle
- The ListStyle
object
Example
const style = new ListStyle('Contents');
style.setConsecutiveNumbering(true); // true
Since: 0.11.0
listStyle.createBulletListLevelStyle(level)
⇒ BulletListLevelStyle
The createBulletListLevelStyle()
method creates a new BulletListLevelStyle
instance for the given list level.
If a list level style for this level already exists, the existing style will be overwritten.
- level
number
The level of the list style, starting with1
Return value
BulletListLevelStyle
- A new BulletListLevelStyle
instance with the specified level
Throws:
Error
if the given list level is invalid
Example
const style = new ListStyle('Contents');
style.createBulletListLevelStyle(3);
Since: 0.11.0
listStyle.getListLevelStyle(level)
⇒ BulletListLevelStyle
| undefined
The getListLevelStyle()
method returns the list level style for the given list level.
If a list level style for this level already exists, the existing style will be overwritten.
- level
number
The level of the list style, starting with1
Return value
BulletListLevelStyle
| undefined
- The list level style for the specified level or undefined
if no list level style is defined for the specified level
Example
const style = new ListStyle('Contents');
style.getListLevelStyle(3);
Since: 0.11.0
listStyle.getListLevelStyles()
⇒ Array.<BulletListLevelStyle>
The getListLevelStyles()
method returns a new Array
object that contains all list level styles of a list style.
Return value
Array.<BulletListLevelStyle>
- A new Array
object that contains the list level styles of a list style
Example
const style = new ListStyle('Contents');
style.createBulletListLevelStyle(1);
style.createBulletListLevelStyle(2);
styles.getListLevelStyles();
Since: 0.11.0
listStyle.removeListLevelStyle(level)
⇒ ListStyle
The removeListLevelStyle()
method removes the list level style for the given list level.
- level
number
The level of the list style, starting with1
Return value
ListStyle
- The ListStyle
object
Example
const style = new ListStyle('Contents');
style.createBulletListLevelStyle(3);
style.removeListLevelStyle(3);
styles.getListLevelStyles(); // []
Since: 0.11.0
This class represents a style.
It is used to specify the formatting of a document or a portion of a document. The unique name of a style can be used to apply a formatting to elements.
Since: 0.9.0
- Style
new Style(displayName, family)
.setClass(clazz)
⇒Style
.getClass()
⇒string
|undefined
.getDisplayName()
⇒string
.getFamily()
⇒string
.getName()
⇒string
Creates a Style
instance that represents the formatting of a document or a portion of a document.
- displayName
string
The unique display name for the style - family
StyleFamily
The family of the style
Example
const style = new Style('Summary', StyleFamily.Paragraph);
style.setClass(clazz)
⇒ Style
The setClass()
method sets the name of the style class.
- clazz
string
|undefined
The name of the style class of the style orundefined
to unset the style class
Return value
Style
- The Style
object
Example
const style = new Style('Text body', StyleFamily.Paragraph);
style.setClass('text'); // 'text'
style.setClass(undefined); // undefined
Since: 0.9.0
The getClass()
method returns name of the style class.
Return value
string
| undefined
- The name of the style class of the style or undefined
if the style class is not set
Example
const style = new Style('Text body', StyleFamily.Paragraph);
style.getClass(); // undefined
style.setClass('text');
style.getClass(); // 'text'
Since: 0.9.0
The getDisplayName()
method returns the name of a style as it should appear in the user interface.
Return value
string
- The pretty and user-friendly name of a style
Example
const style = new Style('Text body', StyleFamily.Paragraph);
style.getDisplayName(); // 'Text body'
Since: 0.9.0
The getFamily()
method returns the family of the style.
Return value
string
- The family of the style
Example
const style = new Style('Text body', StyleFamily.Paragraph);
style.getFamily(); // 'paragraph'
Since: 0.9.0
The getName()
method returns the unique name of the style.
Non-alphanumeric characters in the display name are converted to hexadecimal and wrapped in underscores.
Thus blanks are converted to _20_
.
Return value
string
- A string that identifies the style in this document
Example
const style = new Style('Text body', StyleFamily.Paragraph);
style.getName(); // 'Text_20_body'
Since: 0.9.0
This class represents a tab stop.
Tab stops are used to align text in a paragraph. To become effective they must be set to the style of the respective paragraph.
Since: 0.3.0
- TabStop
new TabStop(position, [type])
.getChar()
⇒string
|undefined
.setChar(char)
⇒TabStop
.getLeaderColor()
⇒Color
|undefined
.setLeaderColor(color)
⇒TabStop
.getLeaderStyle()
⇒TabStopLeaderStyle
.setLeaderStyle(leaderStyle)
⇒TabStop
.getPosition()
⇒number
.setPosition(position)
⇒TabStop
.getType()
⇒TabStopType
.setType(type)
⇒TabStop
Creates a TabStop
instance that represents the settings of a tab stop.
- position
number
The position of the tab stop in millimeters relative to the left margin. If a negative value is given, theposition
will be set to0
. - [type]
TabStopType
= TabStopType.Left
The type of the tab stop
Example
const tabStop = new TabStop(23); // 23mm, TabStopType.Left
const tabStop = new TabStop(23, TabStopType.Center); // 23mm, TabStopType.Center
The getChar()
method returns delimiter character for tab stops of type char
.
Return value
string
| undefined
- The delimiter character or undefined
if the delimiter character is not set
Example
const tabStop = new TabStop(23, TabStopType.Char);
tabStop.getChar(); // undefined
tabStop.setChar('~');
tabStop.getChar(); // '~'
Since: 0.10.0
tabStop.setChar(char)
⇒ TabStop
The setChar()
method sets the delimiter character for tab stops of type char
.
If an illegal value is provided, the value will be ignored.
- char
string
|undefined
The delimiter character orundefined
to unset the delimiter character
Return value
TabStop
- The TabStop
object
Example
const tabStop = new TabStop(23, TabStopType.Char);
tabStop.setChar('~'); // '~'
tabStop.setChar('foo'); // '~'
tabStop.setChar(undefined); // undefined
Since: 0.10.0
tabStop.getLeaderColor()
⇒ Color
| undefined
The getLeaderColor()
method returns the color of a leader line.
Return value
Color
| undefined
- The color of a leader line or undefined
if the current text color will be used
Example
const tabStop = new TabStop(23);
tabStop.getLeaderColor(); // `undefined`
tabStop.setLeaderColor(Color.fromRgb(255, 128, 0));
tabStop.getLeaderColor(); // yellow color
Since: 0.10.0
tabStop.setLeaderColor(color)
⇒ TabStop
The setLeaderColor()
method sets the color of a leader line.
- color
Color
|undefined
The color of a leader line orundefined
if the current text color will be used
Return value
TabStop
- The TabStop
object
Example
const tabStop = new TabStop(23);
tabStop.setLeaderColor(Color.fromRgb(255, 128, 0));
tabStop.setLeaderColor(undefined);
Since: 0.10.0
The getLeaderStyle()
method returns the style for a leader line.
Return value
TabStopLeaderStyle
- The style for a leader line
Example
const tabStop = new TabStop(23);
tabStop.getLeaderStyle(); // TabStopLeaderStyle.None
tabStop.setLeaderStyle(TabStopLeaderStyle.Dotted);
tabStop.getLeaderStyle(); // TabStopLeaderStyle.Dotted
Since: 0.10.0
tabStop.setLeaderStyle(leaderStyle)
⇒ TabStop
The setLeaderStyle()
method sets the style for a leader line.
- leaderStyle
TabStopLeaderStyle
The style for a leader line
Return value
TabStop
- The TabStop
object
Example
const tabStop = new TabStop(23);
tabStop.setLeaderStyle(TabStopLeaderStyle.Dotted);
Since: 0.10.0
The getPosition
method returns the position of the tab stop which is interpreted as being relative
to the left margin or the left indent.
Return value
number
- The position of the tab stop in millimeters
Example
const tabStop = new TabStop(23);
tabStop.getPosition(); // 23
tabStop.setPosition(42);
tabStop.getPosition(); // 42
Since: 0.3.0
tabStop.setPosition(position)
⇒ TabStop
The setPosition
method sets the position of the tab stop which is interpreted as being relative
to the left margin or the left indent.
- position
number
The position of the tab stop in millimeters. If a negative value is given, theposition
will be set to0
.
Return value
TabStop
- The TabStop
object
Example
const tabStop = new TabStop(23); // 23 mm
tabStop.setPosition(42); // 42 mm
tabStop.setPosition(-7); // 0 mm
Since: 0.3.0
The getType
method returns the type of the tab stop.
Return value
TabStopType
- The type of the tab stop
Example
const tabStop = new TabStop(23);
font.getType(); // TabStopType.Left
font.setType(TabStopType.Center);
font.getType(); // TabStopType.Center
Since: 0.3.0
tabStop.setType(type)
⇒ TabStop
The setType
method sets the type of the tab stop.
- type
TabStopType
The type of the tab stop
Return value
TabStop
- The TabStop
object
Example
const tabStop = new TabStop(23); // TabStopType.Left
tabStop.setType(TabStopType.Center); // TabStopType.Center
Since: 0.3.0
Heading ⇐ Paragraph
This class represents a heading in a document.
It is used to structure a document into multiple sections. A chapter or section begins with a heading and extends to the next heading at the same or higher level.
Extends: Paragraph
Since: 0.1.0
- Heading ⇐
Paragraph
new Heading([text], [level])
.setLevel(level)
⇒Heading
.getLevel()
⇒number
.addText(text)
⇒Paragraph
.getText()
⇒string
.setText(text)
⇒Paragraph
.addHyperlink(text, uri)
⇒Hyperlink
.addImage(path)
⇒Image
.setStyle(style)
⇒Paragraph
.getStyle()
⇒ParagraphStyle
|undefined
.setStyleName(styleName)
⇒Paragraph
.getStyleName()
⇒string
|undefined
Creates a Heading
instance that represents a heading in a document.
- [text]
string
= "''"
The text content of the heading; defaults to an empty string if omitted - [level]
number
= 1
The level of the heading, starting with1
; defaults to1
if omitted
Example
new Heading('First Headline', 1);
new Heading('First Headline');
new Heading();
heading.setLevel(level)
⇒ Heading
The setLevel()
method sets the level of the heading, starting with 1
.
If an illegal value is provided, then the heading is assumed to be at level 1
.
- level
number
The level of the heading, starting with1
Return value
Heading
- The Heading
object
Since: 0.1.0
The getLevel()
method returns the level of the heading.
Return value
number
- The level of the heading
Since: 0.1.0
heading.addText(text)
⇒ Paragraph
Appends the specified text to the end of the paragraph.
Overrides: addText
- text
string
The additional text content
Return value
Paragraph
- The Paragraph
object
Example
new Paragraph('Some text') // Some text
.addText('\nEven more text'); // Some text\nEven more text
Since: 0.1.0
Returns the text content of the paragraph. Note: This will only return the text; other elements and markup will be omitted.
Overrides: getText
Return value
string
- The text content of the paragraph
Example
const paragraph = new Paragraph('Some text, ');
paragraph.addHyperlink('some linked text');
paragraph.addText(', even more text');
paragraph.getText(); // Some text, some linked text, even more text
Since: 0.1.0
heading.setText(text)
⇒ Paragraph
Sets the text content of the paragraph. Note: This will replace any existing content of the paragraph.
Overrides: setText
- text
string
The new text content
Return value
Paragraph
- The Paragraph
object
Example
new Paragraph('Some text') // Some text
.setText('Some other text'); // Some other text
Since: 0.1.0
heading.addHyperlink(text, uri)
⇒ Hyperlink
Appends the specified text as hyperlink to the end of the paragraph.
Overrides: addHyperlink
- text
string
The text content of the hyperlink - uri
string
The target URI of the hyperlink
Return value
Hyperlink
- The added Hyperlink
object
Example
new Paragraph('Some text, ') // Some text,
.addHyperlink('some linked text'); // Some text, some linked text
Since: 0.3.0
heading.addImage(path)
⇒ Image
Appends the image of the denoted path to the end of the paragraph. The current paragraph will be set as anchor for the image.
Overrides: addImage
- path
string
The path to the image file
Return value
Image
- The added Image
object
Example
new Paragraph('Some text')
.addImage('/home/homer/myself.png');
Since: 0.3.0
heading.setStyle(style)
⇒ Paragraph
Sets the new style of the paragraph.
To reset the style, undefined
must be given.
If style and style name are both set, the custom style will be set and the common style will be ignored.
Overrides: setStyle
- style
ParagraphStyle
|undefined
The new style orundefined
to reset the style
Return value
Paragraph
- The Paragraph
object
Example
new Paragraph('Some text')
.setStyle(new ParagraphStyle());
Since: 0.3.0
Returns the style of the paragraph.
Overrides: getStyle
Return value
ParagraphStyle
| undefined
- The style of the paragraph or undefined
if no style was set
Example
const paragraph = new Paragraph('Some text');
paragraph.getStyle(); // undefined
paragraph.setStyle(new ParagraphStyle());
paragraph.getStyle(); // previously set style
Since: 0.3.0
heading.setStyleName(styleName)
⇒ Paragraph
Sets the name of the common style that should be applied to the paragraph.
To reset the common style, undefined
must be given.
If style and style name are both set, the custom style will be set and the common style will be ignored.
Overrides: setStyleName
- styleName
string
|undefined
The name of the common style orundefined
to reset the common style
Return value
Paragraph
- The Paragraph
object
Example
new Paragraph('Some text')
.setStyleName('Summary');
Since: 0.9.0
Returns the name of the common style of the paragraph.
Overrides: getStyleName
Return value
string
| undefined
- The name of the common style or undefined
if no common style was set
Example
const paragraph = new Paragraph('Some text');
paragraph.getStyleName(); // undefined
paragraph.setStyleName('Summary);
paragraph.getStyleName(); // 'Summary'
Since: 0.3.0
This class represents a hyperlink in a paragraph.
Since: 0.3.0
Creates a hyperlink
- text
string
The text content of the hyperlink - uri
string
The target URI of the hyperlink
Example
new Hyperlink('My website', 'https://example.com/');
hyperlink.setURI(uri)
⇒ Hyperlink
The setURI()
method sets the target URI for this hyperlink.
If an illegal value is provided, the value will be ignored.
- uri
string
The target URI of this hyperlink
Return value
Hyperlink
- The Hyperlink
object
Example
const hyperlink = new Hyperlink('My website', 'https://example.com/');
hyperlink.setURI('https://github.com'); // https://github.com
hyperlink.setURI(''); // https://github.com
Since: 0.3.0
The getURI()
method returns the target URI of this hyperlink.
Return value
string
- The target URI of this hyperlink
Example
const hyperlink = new Hyperlink('My website', 'https://example.com/');
hyperlink.getURI(); // https://example.com
hyperlink.setURI('https://github.com');
hyperlink.getURI(); // https://github.com
Since: 0.3.0
This class represents a list and may contain any number list items.
Since: 0.2.0
- List
new List()
.addItem([item])
⇒ListItem
.getItem(position)
⇒ListItem
|undefined
.getItems()
⇒Array.<ListItem>
.insertItem(position, item)
⇒ListItem
.removeItemAt(position)
⇒ListItem
|undefined
.getStyle()
⇒ListStyle
|undefined
.setStyle(style)
⇒List
.getStyleName()
⇒string
|undefined
.setStyleName(styleName)
⇒List
.clear()
⇒List
.size()
⇒number
Creates a List
instance that represents a list.
Example
new List();
list.addItem([item])
⇒ ListItem
The addItem()
method adds a new list item or adds the specified item to the list.
- [item]
ListItem
The item to add
Return value
ListItem
- The added ListItem
object
Example
const list = new List();
list.addItem();
list.addItem(new ListItem());
Since: 0.2.0
list.getItem(position)
⇒ ListItem
| undefined
The getItem()
method returns the item at the specified position in the list.
If an invalid position is given, undefined is returned.
- position
number
The index of the requested list item (starting from 0).
Return value
ListItem
| undefined
- The ListItem
object at the specified position
or undefined
if there is no list item at the specified position
Example
const list = new List();
list.addItem();
list.addItem();
list.getItem(1); // second item
list.getItem(2); // undefined
Since: 0.2.0
list.getItems()
⇒ Array.<ListItem>
The getItems()
method returns all list items.
Return value
Array.<ListItem>
- A copy of the list of ListItem
objects
Example
const list = new List();
list.getItems(); // []
list.addItem();
list.addItem();
list.getItems(); // [first item, second item]
Since: 0.2.0
list.insertItem(position, item)
⇒ ListItem
The insertItem
method inserts the specified item at the specified position.
The item is inserted before the item at the specified position.
If the position is greater than the current number of items, the new item is appended at the end of the list. If the position is negative, the new item is inserted as first element.
- position
number
The index at which to insert the list item (starting from 0). - item
ListItem
The item to insert
Return value
ListItem
- The inserted ListItem
object
Example
const list = new List();
list.addItem();
list.insertItem(0, new ListItem()); // insert before existing item
Since: 0.2.0
list.removeItemAt(position)
⇒ ListItem
| undefined
The removeItemAt()
method removes the list item from the specified position.
- position
number
The index of the list item to remove (starting from 0).
Return value
ListItem
| undefined
- The removed ListItem
object
or undefined if there is no list item at the specified position
Example
const list = new List();
list.addItem();
list.addItem();
list.removeItemAt(0); // first item
list.getItems(); // [second item]
list.removeItemAt(2); // undefined
Since: 0.2.0
list.getStyle()
⇒ ListStyle
| undefined
Returns the style of the list.
Return value
ListStyle
| undefined
- The style of the list or undefined
if no style was set
Example
const list = new List();
list.getStyle(); // undefined
list.setStyle(new ListStyle());
list.getStyle(); // previously set style
Since: 0.11.0
list.setStyle(style)
⇒ List
Sets the new style of the list.
To reset the style, undefined
must be given.
If style and style name are both set, the custom style will be set and the common style will be ignored.
- style
ListStyle
|undefined
The new style orundefined
to reset the style
Return value
List
- The List
object
Example
new List()
.setStyle(new ListStyle());
Since: 0.11.0
Returns the name of the common style of the list.
Return value
string
| undefined
- The name of the common style or undefined
if no common style was set
Example
const list = new List();
list.getStyleName(); // undefined
list.setStyleName('Summary');
list.getStyleName(); // 'Summary'
Since: 0.11.0
list.setStyleName(styleName)
⇒ List
Sets the name of the common style that should be applied to the list.
To reset the common style, undefined
must be given.
If style and style name are both set, the custom style will be set and the common style will be ignored.
- styleName
string
|undefined
The name of the common style orundefined
to reset the common style
Return value
List
- The List
object
Example
new List()
.setStyleName('Summary');
Since: 0.11.0
list.clear()
⇒ List
The clear()
method removes all items from the list.
Return value
List
- The List
object
Example
const list = new List();
list.addItem();
list.addItem();
list.clear();
list.getItems(); // []
Since: 0.2.0
The size()
method returns the number of items in the list.
Return value
number
- The number of items in this list
Example
const list = new List();
list.size(); // 0
list.addItem();
list.addItem();
list.size(); // 2
Since: 0.2.0
This class represents an item in a list.
Since: 0.2.0
Creates a ListItem
instance that represents an item in a list.
Example
new ListItem();
listItem.addHeading([text], [level])
⇒ Heading
Adds a heading at the end of the list item. If a text is given, this will be set as text content of the heading.
- [text]
string
The text content of the heading - [level]
number
= 1
The heading level; defaults to 1 if omitted
Return value
Heading
- The newly added heading
Since: 0.11.0
listItem.addList()
⇒ List
Adds an empty list at the end of the list item.
Return value
List
- The newly added list
Example
new ListItem()
.addList();
Since: 0.11.0
listItem.addParagraph([text])
⇒ Paragraph
Adds a paragraph at the end of the list item. If a text is given, this will be set as text content of the paragraph.
- [text]
string
The text content of the paragraph
Return value
Paragraph
- The newly added paragraph
Since: 0.11.0
This class represents a paragraph.
Since: 0.1.0
- Paragraph
new Paragraph([text])
.addText(text)
⇒Paragraph
.getText()
⇒string
.setText(text)
⇒Paragraph
.addHyperlink(text, uri)
⇒Hyperlink
.addImage(path)
⇒Image
.setStyle(style)
⇒Paragraph
.getStyle()
⇒ParagraphStyle
|undefined
.setStyleName(styleName)
⇒Paragraph
.getStyleName()
⇒string
|undefined
Creates a Paragraph
instance.
- [text]
string
The text content of the paragraph; defaults to an empty string if omitted
Example
new Paragraph('Some text');
new Paragraph();
paragraph.addText(text)
⇒ Paragraph
Appends the specified text to the end of the paragraph.
- text
string
The additional text content
Return value
Paragraph
- The Paragraph
object
Example
new Paragraph('Some text') // Some text
.addText('\nEven more text'); // Some text\nEven more text
Since: 0.1.0
Returns the text content of the paragraph. Note: This will only return the text; other elements and markup will be omitted.
Return value
string
- The text content of the paragraph
Example
const paragraph = new Paragraph('Some text, ');
paragraph.addHyperlink('some linked text');
paragraph.addText(', even more text');
paragraph.getText(); // Some text, some linked text, even more text
Since: 0.1.0
paragraph.setText(text)
⇒ Paragraph
Sets the text content of the paragraph. Note: This will replace any existing content of the paragraph.
- text
string
The new text content
Return value
Paragraph
- The Paragraph
object
Example
new Paragraph('Some text') // Some text
.setText('Some other text'); // Some other text
Since: 0.1.0
paragraph.addHyperlink(text, uri)
⇒ Hyperlink
Appends the specified text as hyperlink to the end of the paragraph.
- text
string
The text content of the hyperlink - uri
string
The target URI of the hyperlink
Return value
Hyperlink
- The added Hyperlink
object
Example
new Paragraph('Some text, ') // Some text,
.addHyperlink('some linked text'); // Some text, some linked text
Since: 0.3.0
paragraph.addImage(path)
⇒ Image
Appends the image of the denoted path to the end of the paragraph. The current paragraph will be set as anchor for the image.
- path
string
The path to the image file
Return value
Image
- The added Image
object
Example
new Paragraph('Some text')
.addImage('/home/homer/myself.png');
Since: 0.3.0
paragraph.setStyle(style)
⇒ Paragraph
Sets the new style of the paragraph.
To reset the style, undefined
must be given.
If style and style name are both set, the custom style will be set and the common style will be ignored.
- style
ParagraphStyle
|undefined
The new style orundefined
to reset the style
Return value
Paragraph
- The Paragraph
object
Example
new Paragraph('Some text')
.setStyle(new ParagraphStyle());
Since: 0.3.0
Returns the style of the paragraph.
Return value
ParagraphStyle
| undefined
- The style of the paragraph or undefined
if no style was set
Example
const paragraph = new Paragraph('Some text');
paragraph.getStyle(); // undefined
paragraph.setStyle(new ParagraphStyle());
paragraph.getStyle(); // previously set style
Since: 0.3.0
paragraph.setStyleName(styleName)
⇒ Paragraph
Sets the name of the common style that should be applied to the paragraph.
To reset the common style, undefined
must be given.
If style and style name are both set, the custom style will be set and the common style will be ignored.
- styleName
string
|undefined
The name of the common style orundefined
to reset the common style
Return value
Paragraph
- The Paragraph
object
Example
new Paragraph('Some text')
.setStyleName('Summary');
Since: 0.9.0
Returns the name of the common style of the paragraph.
Return value
string
| undefined
- The name of the common style or undefined
if no common style was set
Example
const paragraph = new Paragraph('Some text');
paragraph.getStyleName(); // undefined
paragraph.setStyleName('Summary);
paragraph.getStyleName(); // 'Summary'
Since: 0.3.0