Skip to main content

Using command line arguments

You can pass arguments to your script using the --argument flag. Arguments are passed as a JSON object and accessed via the global Argument object.

note

This is the same as using the SetProperty method.

docbuilder.exe "--argument={\"company\":\"ONLYOFFICE\",\"product\":\"Document Builder\"}" "script.js"

Access these arguments in your script using the global Argument object:

const sCompany = Argument["company"];
const sProduct = Argument["product"];

Example

docbuilder.exe "--argument={\"company\":\"ONLYOFFICE\",\"product\":\"Document Builder\",\"compatibility\":\"100%\"}" "sample_with_arguments.js"

sample_with_arguments.js:

builderJS.CreateFile("docx");

const sCompany = Argument["company"];
const sProduct = Argument["product"];
const sCompatibility = Argument["compatibility"];

const oDocument = Api.GetDocument();
const oParagraph = oDocument.GetElement(0);
oParagraph.AddText("This is an example of using command line arguments with ONLYOFFICE Document Builder.");
oParagraph.AddLineBreak();
oParagraph.AddLineBreak();
oParagraph.AddText("Company name: " + sCompany);
oParagraph.AddLineBreak();
oParagraph.AddText("Product: " + sProduct);
oParagraph.AddLineBreak();
oParagraph.AddText("Compatibility with OOXML standards: " + sCompatibility);

builderJS.SaveFile("docx", "ArgumentUse.docx");
builderJS.CloseFile();