Skip to main content

AddCaptionCrossRef

Adds a caption cross-reference to the current paragraph. 💡 Please note that this paragraph must be in the document.

Syntax

expression.AddCaptionCrossRef(sCaption, sRefType, oParaTo, bLink, bAboveBelow);

expression - A variable that represents a ApiParagraph class.

Parameters

NameRequired/OptionalData typeDefaultDescription
sCaptionRequiredCaptionLabelstring
sRefTypeRequiredcaptionRefToThe text or numeric value of a caption reference you want to insert.
oParaToRequiredApiParagraphThe caption paragraph to be referred to (must be in the document).
bLinkOptionalbooleantrueSpecifies if the reference will be inserted as a hyperlink.
bAboveBelowOptionalbooleanfalseSpecifies if the above/below words indicating the position of the reference should be included (used only with the "pageNum" sRefType).

Returns

boolean

Example

This example adds a caption cross-reference to the paragraph.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let drawing = Api.CreateImage("https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png", 60 * 36000, 35 * 36000);
paragraph.AddDrawing(drawing);
paragraph = Api.CreateParagraph();
doc.Push(paragraph);
paragraph.AddCaption("", "Figure", false, "Arabic", false, undefined, "hyphen");
paragraph = Api.CreateParagraph();
doc.Push(paragraph);
paragraph.AddText('Link to ');
let captionParagraphs = doc.GetAllCaptionParagraphs("Figure");
paragraph.AddCaptionCrossRef("Figure", "entireCaption", captionParagraphs[0], true, false);