Skip to content

Latest commit

 

History

History
3277 lines (2387 loc) · 93.3 KB

API.md

File metadata and controls

3277 lines (2387 loc) · 93.3 KB

Classes

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.

HeadingParagraph

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.

Image

This class represents an image in a paragraph.

It is used to embed image data in BASE64 encoding.

Since: 0.3.0


new Image(path)

Creates an image

Parameters

  • 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.

Parameters

  • 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


image.getAnchorType()AnchorType

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.

Parameters

  • 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


image.getHeight()number | undefined

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


image.getPath()string

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.

Parameters

  • 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.

Parameters

  • 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


image.getWidth()number | undefined

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


Meta

This class represents the metadata of a document.

It is used to set descriptive information about the document.

Since: 0.6.0


new Meta()

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.

Parameters

  • creator string | undefined
    The name of the person who last modified a document or undefined 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


meta.getCreator()string | undefined

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


meta.getCreationDate()Date

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.

Parameters

  • date Date | undefined
    A Date instance specifying the date and time when the document was last modified or undefined 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


meta.getDate()Date | undefined

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.

Parameters

  • description string | undefined
    The description of the document or undefined 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


meta.getDescription()string | undefined

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


meta.getEditingCycles()number

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


meta.getGenerator()string

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.

Parameters

  • initialCreator string | undefined
    The name of the initial creator of the document or undefined 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


meta.getInitialCreator()string | undefined

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.

Parameters

  • 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


meta.getKeywords()Array.<string>

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.

Parameters

  • 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.

Parameters

  • language string | undefined
    The default language of the document or undefined 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


meta.getLanguage()string | undefined

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.

Parameters

  • printDate Date | undefined
    A Date instance specifying the date and time when the document was last printed or undefined 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


meta.getPrintDate()Date | undefined

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.

Parameters

  • printedBy string | undefined
    The name of the last person who printed the document or undefined 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


meta.getPrintedBy()string | undefined

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.

Parameters

  • subject string | undefined
    The subject of the document or undefined 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


meta.getSubject()string | undefined

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.

Parameters

  • title string | undefined
    The title of the document or undefined 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


meta.getTitle()string | undefined

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


CommonStyles

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


new CommonStyles()

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.

Parameters

  • 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


commonStyles.createParagraphStyle(name)ParagraphStyle

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.

Parameters

  • 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


commonStyles.getName(displayName)string | undefined

The getName() method returns the unique name of the style with the specified display name.

Parameters

  • 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


commonStyles.getAll()


FontFaceDeclarations

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

Creates a FontFace object with the given name. If a font with this name already exists, the existing font will be returned.

Parameters

  • 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.

Parameters

  • 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.

Parameters

  • 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


TextBody

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.

Parameters

  • [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.

Parameters

  • [text] string
    The text content of the paragraph

Return value
Paragraph - The newly added paragraph

Since: 0.7.0


TextDocument

This class represents a text document in OpenDocument format.

Since: 0.1.0


new TextDocument()

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


textDocument.getMimeType()string

The getMimeType() method returns the document type of the document.

Return value
string - The document type of the document

Example

new TextDocument()
  .getMimeType(); // application/vnd.oasis.opendocument.text

Since: 2.1.0


textDocument.getOfficeVersion()string

The getOfficeVersion() method returns the version of the OpenDocument specification to which this document comprises.

Return value
string - The version of the OpenDocument specification

Example

new TextDocument()
  .getOfficeVersion(); // 1.2

Since: 2.1.0


textDocument.saveFlat(filePath)Promise.<void>

The saveFlat() method converts the document into an XML string and stores it in flat open document xml format.

Parameters

  • filePath string
    The file path to write to

Example

new TextDocument()
  .saveFlat('/home/homer/document.fodt');

Since: 0.1.0


textDocument.toString()string

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


BulletListLevelStyle

This class represents a list style where list items are preceded by bullets.

Since: 0.11.0


new BulletListLevelStyle(level)

Creates a BulletListLevelStyle instance that represents a list style where list items are preceded by bullets.

Parameters

  • level number
    The level of the list style, starting with 1

Example

const style = new BulletListLevelStyle(3);

bulletListLevelStyle.getBulletChar()string

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.

Parameters

  • 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


bulletListLevelStyle.getLevel()number

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


bulletListLevelStyle.getNumberPrefix()string | undefined

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.

Parameters

  • prefix string | undefined
    The character to display before a bullet or undefined 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


bulletListLevelStyle.getNumberSuffix()string | undefined

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.

Parameters

  • suffix string | undefined
    The character to display after a bullet or undefined 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


bulletListLevelStyle.getRelativeBulletSize()string | undefined

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.

Parameters

  • relativeSize string | undefined
    The percentage value for the bullet size or undefined 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


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.

Since: 0.8.0


new FontFace(name, [fontFamily], [fontPitch])

Creates a FontFace instance that represents the characteristics of a font.

Parameters

  • 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.

Parameters

  • fontCharset string | undefined
    The charset of the font or undefined 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


fontFace.getCharset()string | undefined

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.

Parameters

  • fontFamily string | undefined
    The font family of the font or undefined 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


fontFace.getFontFamily()string | undefined

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.

Parameters

  • fontFamilyGeneric FontFamilyGeneric | undefined
    The generic font family name or undefined 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


fontFace.getFontFamilyGeneric()string | undefined

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.

Parameters

  • fontPitch FontPitch | undefined
    The pitch of the font or undefined 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


fontFace.getFontPitch()string | undefined

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


fontFace.getName()string

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


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.

Since: 0.11.0


new ListStyle(displayName)

Creates a ListStyle instance that represents the formatting of a list.

Parameters

  • displayName string
    The unique display name for the style

Example

const style = new ListStyle('Contents');

listStyle.getConsecutiveNumbering()boolean

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.

Parameters

  • consecutiveNumbering boolean
    true if consecutive numbering is used for all list levels or false 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.

Parameters

  • level number
    The level of the list style, starting with 1

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.

Parameters

  • level number
    The level of the list style, starting with 1

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.

Parameters

  • level number
    The level of the list style, starting with 1

Return value
ListStyle - The ListStyle object

Example

const style = new ListStyle('Contents');
style.createBulletListLevelStyle(3);
style.removeListLevelStyle(3);
styles.getListLevelStyles();             // []

Since: 0.11.0


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.

Since: 0.9.0


new Style(displayName, family)

Creates a Style instance that represents the formatting of a document or a portion of a document.

Parameters

  • 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.

Parameters

  • clazz string | undefined
    The name of the style class of the style or undefined 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


style.getClass()string | undefined

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


style.getDisplayName()string

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


style.getFamily()string

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


style.getName()string

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


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.

Since: 0.3.0


new TabStop(position, [type])

Creates a TabStop instance that represents the settings of a tab stop.

Parameters

  • position number
    The position of the tab stop in millimeters relative to the left margin. If a negative value is given, the position will be set to 0.
  • [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

tabStop.getChar()string | undefined

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.

Parameters

  • char string | undefined
    The delimiter character or undefined 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.

Parameters

  • color Color | undefined
    The color of a leader line or undefined 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


tabStop.getLeaderStyle()TabStopLeaderStyle

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.

Parameters

  • 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


tabStop.getPosition()number

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.

Parameters

  • position number
    The position of the tab stop in millimeters. If a negative value is given, the position will be set to 0.

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


tabStop.getType()TabStopType

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.

Parameters

  • 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


new Heading([text], [level])

Creates a Heading instance that represents a heading in a document.

Parameters

  • [text] string = "''"
    The text content of the heading; defaults to an empty string if omitted
  • [level] number = 1
    The level of the heading, starting with 1; defaults to 1 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.

Parameters

  • level number
    The level of the heading, starting with 1

Return value
Heading - The Heading object

Since: 0.1.0


heading.getLevel()number

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

Parameters

  • 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


heading.getText()string

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

Parameters

  • 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

Parameters

  • 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

Parameters

  • 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

Parameters

  • style ParagraphStyle | undefined
    The new style or undefined to reset the style

Return value
Paragraph - The Paragraph object

Example

new Paragraph('Some text')
  .setStyle(new ParagraphStyle());

Since: 0.3.0


heading.getStyle()ParagraphStyle | undefined

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

Parameters

  • styleName string | undefined
    The name of the common style or undefined to reset the common style

Return value
Paragraph - The Paragraph object

Example

new Paragraph('Some text')
  .setStyleName('Summary');

Since: 0.9.0


heading.getStyleName()string | undefined

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


Hyperlink

This class represents a hyperlink in a paragraph.

Since: 0.3.0


new Hyperlink(text, uri)

Creates a hyperlink

Parameters

  • 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.

Parameters

  • 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


hyperlink.getURI()string

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


List

This class represents a list and may contain any number list items.

Since: 0.2.0


new List()

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.

Parameters

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.

Parameters

  • 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.

Parameters

  • 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.

Parameters

  • 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.

Parameters

  • style ListStyle | undefined
    The new style or undefined to reset the style

Return value
List - The List object

Example

new List()
  .setStyle(new ListStyle());

Since: 0.11.0


list.getStyleName()string | undefined

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.

Parameters

  • styleName string | undefined
    The name of the common style or undefined 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


list.size()number

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


ListItem

This class represents an item in a list.

Since: 0.2.0


new ListItem()

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.

Parameters

  • [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.

Parameters

  • [text] string
    The text content of the paragraph

Return value
Paragraph - The newly added paragraph

Since: 0.11.0


Paragraph

This class represents a paragraph.

Since: 0.1.0


new Paragraph([text])

Creates a Paragraph instance.

Parameters

  • [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.

Parameters

  • 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


paragraph.getText()string

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.

Parameters

  • 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.

Parameters

  • 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.

Parameters

  • 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.

Parameters

  • style ParagraphStyle | undefined
    The new style or undefined to reset the style

Return value
Paragraph - The Paragraph object

Example

new Paragraph('Some text')
  .setStyle(new ParagraphStyle());

Since: 0.3.0


paragraph.getStyle()ParagraphStyle | undefined

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.

Parameters

  • styleName string | undefined
    The name of the common style or undefined to reset the common style

Return value
Paragraph - The Paragraph object

Example

new Paragraph('Some text')
  .setStyleName('Summary');

Since: 0.9.0


paragraph.getStyleName()string | undefined

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