How to Set Default Format in JavaScript DOCX Editor
28 Aug 20264 minutes to read
You can set the default character format, paragraph format, and section format in JavaScript DOCX Editor (Document Editor).
Set the default character format
You can use setDefaultCharacterFormat method to set the default character format. For example, the DOCX Editor’s default font size is 11 and you can change it to any valid value.
The following example code illustrates how to change the default font size in the DOCX Editor.
var container = new ej.documenteditor.DocumentEditorContainer({ height: "590px" });
container.serviceUrl = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';
ej.documenteditor.DocumentEditorContainer.Inject(ej.documenteditor.Toolbar);
// Default font size set to 20
container.setDefaultCharacterFormat({ fontSize: 20 });
container.appendTo('#container');NOTE
The Web API hosted link
https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/utilized in the DOCX Editor’s serviceUrl property is intended solely for demonstration and evaluation purposes. For production deployment, please host your own web service with your required server configurations. You can refer and reuse the GitHub Web Service example or Docker image for hosting your own web service and use for the serviceUrl property.
Similarly, you can change the required CharacterFormatProperties default values.
The following example code illustrates how to change the other character format default values in the DOCX Editor.
var container = new ej.documenteditor.DocumentEditorContainer({ height: "590px" });
container.serviceUrl = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';
ej.documenteditor.DocumentEditorContainer.Inject(ej.documenteditor.Toolbar);
// Set default value
var defaultCharacterFormat = {
bold: false,
italic: false,
baselineAlignment: 'Normal',
underline: 'None',
fontColor: "#000000",
fontFamily: 'Algerian',
fontSize: 12
};
container.setDefaultCharacterFormat(defaultCharacterFormat);
container.appendTo('#container');NOTE
The Web API hosted link
https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/utilized in the DOCX Editor’s serviceUrl property is intended solely for demonstration and evaluation purposes. For production deployment, please host your own web service with your required server configurations. You can refer and reuse the GitHub Web Service example or Docker image for hosting your own web service and use for the serviceUrl property.
Set the default paragraph format
You can use setDefaultParagraphFormat API to set the default paragraph format. You can change the required ParagraphFormatProperties default values.
The following example code illustrates how to change the paragraph format (before spacing, line spacing, etc.) default values in the DOCX Editor.
var container = new ej.documenteditor.DocumentEditorContainer({ height: "590px" });
container.serviceUrl = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';
ej.documenteditor.DocumentEditorContainer.Inject(ej.documenteditor.Toolbar);
var defaultParagraphFormat = {
beforeSpacing: 8,
lineSpacing: 1.5,
leftIndent: 24,
textAlignment: "Center"
};
container.setDefaultParagraphFormat(defaultParagraphFormat);
container.appendTo('#container');NOTE
The Web API hosted link
https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/utilized in the DOCX Editor’s serviceUrl property is intended solely for demonstration and evaluation purposes. For production deployment, please host your own web service with your required server configurations. You can refer and reuse the GitHub Web Service example or Docker image for hosting your own web service and use for the serviceUrl property.
Set the default section format
You can use setDefaultSectionFormat API to set the default section format. You can change the required SectionFormatProperties default values.
The following example code illustrates how to change the section format (header and footer distance, page width and height, etc.) default values in the DOCX Editor.
var container = new ej.documenteditor.DocumentEditorContainer({ height: "590px" });
container.serviceUrl = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';
ej.documenteditor.DocumentEditorContainer.Inject(ej.documenteditor.Toolbar);
var defaultSectionFormat = {
pageWidth: 500,
pageHeight: 800,
headerDistance: 56,
footerDistance: 48,
leftMargin: 24,
rightMargin: 12,
topMargin: 0,
bottomMargin: 0
};
container.setDefaultSectionFormat(defaultSectionFormat);
container.appendTo('#container');NOTE
The Web API hosted link
https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/utilized in the DOCX Editor’s serviceUrl property is intended solely for demonstration and evaluation purposes. For production deployment, please host your own web service with your required server configurations. You can refer and reuse the GitHub Web Service example or Docker image for hosting your own web service and use for the serviceUrl property.