Skip to main content

AddCaption

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

Syntax

expression.AddCaption(additionalText, label, excludeLabel, numFormat, isBefore, headingLvl, captionSep);

expression - A variable that represents a ApiBlockLvlSdt class.

Parameters

NameRequired/OptionalData typeDefaultDescription
additionalTextRequiredstringThe additional text.
labelOptionalCaptionLabel | String"Table"The caption label.
excludeLabelOptionalbooleanfalseSpecifies whether to exclude the label from the caption.
numFormatOptionalCaptionNumberingFormat"Arabic"The possible caption numbering format.
isBeforeOptionalbooleanfalseSpecifies whether to insert the caption before the current content control (true) or after (false) (after/before the shape if it is placed in the shape).
headingLvlOptionalNumberThe heading level (used if you want to specify the chapter number). 💡 If you want to specify "Heading 1", then nHeadingLvl === 0 and etc.
captionSepOptionalCaptionSep"hyphen"The caption separator (used if you want to specify the chapter number).

Returns

boolean

Example

Add a numbered figure caption below a content control in a document.

// How do I label a content control with a figure caption in a document?

// Insert an image into a content control and attach a caption with automatic numbering in a document.

let doc = Api.GetDocument();
let blockLvlSdt = Api.CreateBlockLvlSdt();
let paragraph = Api.CreateParagraph();
let image = Api.CreateImage(
'https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png',
60 * 36000, 60 * 36000
);
paragraph.AddDrawing(image);
blockLvlSdt.AddElement(paragraph, 0);
doc.AddElement(0, blockLvlSdt);
blockLvlSdt.AddCaption('', 'Figure', false, 'Arabic', false, undefined, 'hyphen');