Get Started
Usage API
More information

ToJSON

ToJSON(bWriteDefaultTextPr, bWriteDefaultParaPr, bWriteTheme, bWriteSectionPr, bWriteNumberings, bWriteStyles) → { JSON }

Converts the ApiDocument object into the JSON object.

Parameters:

Name Type Description
bWriteDefaultTextPr boolean

Specifies if the default text properties will be written to the JSON object or not.

bWriteDefaultParaPr boolean

Specifies if the default paragraph properties will be written to the JSON object or not.

bWriteTheme boolean

Specifies if the document theme will be written to the JSON object or not.

bWriteSectionPr boolean

Specifies if the document section properties will be written to the JSON object or not.

bWriteNumberings boolean

Specifies if the document numberings will be written to the JSON object or not.

bWriteStyles boolean

Specifies if the document styles will be written to the JSON object or not.

Returns:

Type
JSON

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
let json = oDocument.ToJSON(true, true, true, true, true, true);
var oDocumentFromJSON = Api.FromJSON(json);
var oParagraph = oDocumentFromJSON[0];
var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 224, 204), 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 164, 101), 100000);
var oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000);
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing1 = Api.CreateShape("rect", 3212465, 963295, oFill, oStroke);
oParagraph.AddDrawing(oDrawing1);
var oDrawing2 = Api.CreateShape("wave", 3212465, 963295, oFill, oStroke);
oParagraph.AddDrawing(oDrawing2);
var aDrawings = oDocumentFromJSON[0].GetAllShapes();
oParagraph = oDocument.GetElement(0);
oParagraph.AddDrawing(aDrawings[0]);
oParagraph.AddLineBreak();
oParagraph.AddText("This is the first shape from the JSON document.");
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();

Resulting document