AddCaptionCrossRef
Adds a caption cross-reference to the current paragraph.
Please note that this paragraph must be in the document.
Parameters:
Name |
Type |
Default |
Description |
sCaption |
CaptionLabel | string
|
|
The caption label ("Equation", "Figure", "Table", or another caption label). |
sRefType |
captionRefTo
|
|
The text or numeric value of a caption reference you want to insert. |
oParaTo |
ApiParagraph
|
|
The caption paragraph to be referred to (must be in the document). |
bLink |
boolean
|
true |
Specifies if the reference will be inserted as a hyperlink. |
bAboveBelow |
boolean
|
false |
Specifies if the above/below words indicating the position of the reference should be included (used only with the "pageNum" sRefType). |
Returns:
- Type
-
boolean
Example
Copy code
builder.CreateFile("docx");
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);
builder.SaveFile("docx", "AddCaptionCrossRef.docx");
builder.CloseFile();
Resulting document