AddCaption

function AddCaption(
  sAdditional: string = null,
  sLabel: CaptionLabel | String = "Table",
  bExludeLabel: boolean = false,
  sNumberingFormat: CaptionNumberingFormat = "Arabic",
  bBefore: boolean = false,
  nHeadingLvl: Number = null,
  sCaptionSep: CaptionSep = "hyphen",
): boolean

Description

Adds a caption paragraph after (or before) the current paragraph. Please note that the current paragraph must be in the document (not in the footer/header). And if the current paragraph is placed in a shape, then a caption is added after (or before) the parent shape.

Parameters

sAdditionalstringdefault: null

The additional text.

sLabelCaptionLabel | Stringdefault: "Table"

The caption label.

bExludeLabelbooleandefault: false

Specifies whether to exclude the label from the caption.

sNumberingFormatCaptionNumberingFormatdefault: "Arabic"

The possible caption numbering format.

bBeforebooleandefault: false

Specifies whether to insert the caption before the current paragraph (true) or after (false) (after/before the shape if it is placed in the shape).

nHeadingLvlNumberdefault: null

The heading level (used if you want to specify the chapter number).If you want to specify "Heading 1", then nHeadingLvl === 0 and etc.

sCaptionSepCaptionSepdefault: "hyphen"

The caption separator (used if you want to specify the chapter number).

Returns

boolean

Try It

var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oDrawing = Api.CreateImage("https://api.onlyoffice.com/content/img/docbuilder/examples/coordinate_aspects.png", 60 * 36000, 35 * 36000);
oParagraph.AddDrawing(oDrawing);
oParagraph = Api.CreateParagraph();
oDocument.Push(oParagraph);
oParagraph.AddCaption("", "Figure", false, "Arabic", false, undefined, "hyphen");

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).