AddCaptionCrossRef

function AddCaptionCrossRef(
  sCaption: CaptionLabel | string = null,
  sRefType: captionRefTo = null,
  oParaTo: ApiParagraph = null,
  bLink: boolean = true,
  bAboveBelow: boolean = false,
): boolean

Description

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

Parameters

sCaptionCaptionLabel | stringdefault: null

The caption label ("Equation", "Figure", "Table", or another caption label).

sRefTypecaptionRefTodefault: null

The text or numeric value of a caption reference you want to insert.

oParaToApiParagraphdefault: null

The caption paragraph to be referred to (must be in the document).

bLinkbooleandefault: true

Specifies if the reference will be inserted as a hyperlink.

bAboveBelowbooleandefault: false

Specifies if the above/below words indicating the position of the reference should be included (used only with the "pageNum" sRefType).

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");
oParagraph = Api.CreateParagraph();
oDocument.Push(oParagraph);
oParagraph.AddText('Link to ');
var aCaptionParagraphs = oDocument.GetAllCaptionParagraphs("Figure");
oParagraph.AddCaptionCrossRef("Figure", "entireCaption", aCaptionParagraphs[0], true, false);

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