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
| Name | Required/Optional | Data type | Default | Description |
|---|---|---|---|---|
| sCaption | Required | CaptionLabel | string | The caption label ("Equation", "Figure", "Table", or another caption label). | |
| sRefType | Required | captionRefTo | The text or numeric value of a caption reference you want to insert. | |
| oParaTo | Required | ApiParagraph | The caption paragraph to be referred to (must be in the document). | |
| bLink | Optional | boolean | true | Specifies if the reference will be inserted as a hyperlink. |
| bAboveBelow | Optional | boolean | false | Specifies 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.
- Code
- Result
// How to create a caption reference to the paragraph.
// Add a cross-reference to the caption of 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, 60 * 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);