# docx-editor-document-protection

> Document editor enabling protected sections, restricted edits, and permission controls.

**Framework:** javascript  **Component:** DocxEditor  **Variant:** document-protection

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/javascript/docx-editor-document-protection.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-documenteditor @syncfusion/ej2-popups
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/docx-editor-document-protection/docx-editor.html

```html
<div>
    <div class="col-lg-9 control-section">
  <div class="content-wrapper">
        <div class="flex-container">
            <label class="switchLabel" for="toolbarSwitch">Ribbon UI</label>
            <div class="e-message render-mode-info">
                <span class="e-msg-icon render-mode-info-icon"                  title="Turn OFF to switch from Ribbon to toolbar UI"></span>
            </div>
            <input cssClass="buttonSwitch" id="toolbarSwitch" change="onChange" type="checkbox" />
        </div>
    </div>
        <div id='documenteditor_titlebar' class="e-de-ctn-title"></div>
        <div id="container"></div>

    </div>
    <div class="col-lg-3 property-section">
        <div class="content-wrapper">
            <div class="heading-section">
                <h5><b>User Permission</b></h5>
            </div>

            <div class="control-label"><b>Current User</b>
            </div>
            <div class="control-label">
                <input type="text" tabindex="1" id='ddlelement' />
            </div>
            <div class="control-label"><b>User Color</b>
            </div>
            <input id="color-picker" type="color">
        </div>
    </div>
</div>

<style>
    .ej2-new {
        height: 590px;
    }
      .flex-container {
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }

    .render-mode-info {
        background: none;
        border: none;
        padding-left: 0px;
    }

    .render-mode-info .render-mode-info-icon {
        height: 16px;
        width: 16px;
    }

    .switchLabel {
        font-family: "Segoe UI", "GeezaPro", "DejaVu Serif", sans-serif;
        font-weight: 400;
        line-height: 20px;
        letter-spacing: 0.24px;
        text-align: right;
        font-size: 14px;
        margin-bottom: 0px;
    }

    .render-mode-info .render-mode-info-icon::before {
        line-height: normal;
    }

    .buttonSwitch {
        Width: 40px;
        Height: 24px;
    }
    #documenteditor_titlebar {
        border-bottom: 1px solid #2B3481;
        height: 36px;
        line-height: 26px;
        width: 100%;
        font-size: 12px;
        padding-left: 15px;
        padding-right: 10px;
        font-family: inherit;
    }

    #documenteditor_title_contentEditor {
        height: 26px;
        max-width: 85%;
        width: auto;
        overflow: hidden;
        display: inline-block;
        padding-left: 4px;
        padding-right: 4px;
        margin: 5px;
    }

    .single-line {
        cursor: text !important;
        outline: none;
    }

    .single-line:hover {
        border-color: #e4e4e4 !important;
    }

    [contenteditable="true"].single-line {
        white-space: nowrap;
        border-color: #e4e4e4 !important;
    }

    .property-panel-table div {
        padding-left: 0px;
    }

    .heading-section {
        padding-bottom: 20px;
        padding-top: 20px;
    }

    .control-label {
        padding-bottom: 15px;
    }

    /** Document editor sample level font icons*/

    @font-face {
        font-family: 'Sample brower icons';
        font-weight: normal;
        font-style: normal;
    }

    [class^="e-de-icon-"],
    [class*=" e-de-icon-"] {
        font-family: 'Sample brower icons' !important;
    }

    .e-de-icon-Print:before {
        content: "\e723";
    }

    .e-de-icon-Download:before {
        content: "\e728";
    }

    /** sample level font icons ends*/
</style>
<script>
    window.addEventListener("beforeunload", onbeforeunload);
    function onbeforeunload() {
        return 'Want to save your changes?';
    };
</script>
```

### src/components/docx-editor-document-protection/docx-editor.ts

```typescript
import { DocumentEditorContainer, Ribbon, Toolbar } from '@syncfusion/ej2-documenteditor';
import {
  createSpinner,
  showSpinner,
  hideSpinner,
} from '@syncfusion/ej2-popups';
import { sfdtdata } from '../datasource/docx-editor-data';

/**
 * Default document editor sample
 */

function formatSave(type: string) {
    createSpinner({
        target: document.getElementById('container'),
    });
    showSpinner(document.getElementById('container'));
    let format: string = type;
    let url = (window as any).container.documentEditor.serviceUrl + 'Export';
    let http = new XMLHttpRequest();
    http.open('POST', url);
    http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
    http.responseType = 'blob';

    let sfdt = {
        Content: (window as any).container.documentEditor.serialize(),
        Filename: (window as any).container.documentEditor.documentName,
        Format: '.' + format,
    };

    http.onload = function () {
        if (http.status === 200) {
            let responseData = http.response;
            let blobUrl = URL.createObjectURL(responseData);
            let downloadLink = document.createElement('a');
            downloadLink.href = blobUrl;
            downloadLink.download =
                (window as any).container.documentEditor.documentName + '.' + format.toLowerCase();
            document.body.appendChild(downloadLink);
            hideSpinner(document.getElementById('container'));
            downloadLink.click();
            document.body.removeChild(downloadLink);
            URL.revokeObjectURL(blobUrl);
        } else {
            console.error('Request failed with status:', http.status);
            hideSpinner(document.getElementById('container'));
        }
    };

    http.send(JSON.stringify(sfdt));
}

export function initDocxEditorDocumentProtection(): void {

    let hostUrl: string = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';

    let container: DocumentEditorContainer = new DocumentEditorContainer({
        toolbarMode: 'Ribbon',
        serviceUrl: hostUrl,
        enableToolbar: true,
        height: '590px',
        documentEditorSettings: { showRuler: true },
        fileMenuItems: [
            'New',
            'Open',
            {
                text: 'Export',
                id: 'custom_item',
                iconCss: 'e-icons e-export',
                items: [
                    { id: 'sfdt', text: 'Syncfusion Document Text (*.sfdt)' },
                    { id: 'docx', text: 'Word Document (*.docx)' },
                    { id: 'dotx', text: 'Word Template (*.dotx)' },
                    { id: 'text', text: 'Plain Text (*.txt)' },
                    { id: 'pdf', text: 'PDF (*.pdf)' },
                    { id: 'html', text: 'HyperText Markup Language (*.html)' },
                    { id: 'rtf', text: 'Rich Text Format (*.rtf)' },
                    { id: 'md', text: 'Markdown (*.md)' },
                    { id: 'odt', text: 'OpenDocument Text (*.odt)' },
                    { id: 'wordml', text: 'Word XML Document (*.xml)' }
                ],
            },
            'Print',
        ],
        fileMenuItemClick: function (args) {
            if (args.item.id) {
                let value: string = args.item.id;
                let sampleName: string = container.documentEditor.documentName === '' ? 'sample' : container.documentEditor.documentName;
                switch (value) {
                    case 'docx':
                        container.documentEditor.save(sampleName, 'Docx');
                        break;
                    case 'sfdt':
                        container.documentEditor.save(sampleName, 'Sfdt');
                        break;
                    case 'text':
                        container.documentEditor.save(sampleName, 'Txt');
                        break;
                    case 'dotx':
                        container.documentEditor.save(sampleName, 'Dotx');
                        break;
                    case 'pdf':
                        formatSave('Pdf');
                        break;
                    case 'html':
                        formatSave('Html');
                        break;
                    case 'odt':
                        formatSave('Odt');
                        break;
                    case 'md':
                        formatSave('Md');
                        break;
                    case 'rtf':
                        formatSave('Rtf');
                        break;
                    case 'wordml':
                        formatSave('Xml');
                        break;
                }
            }
        },
    });
    DocumentEditorContainer.Inject(Toolbar, Ribbon);
    container.appendTo('#container');
    (window as any).container = container;

    container.documentEditor.open(JSON.stringify({ sfdt: sfdtdata }));
    container.documentEditor.documentName = 'Document Protection';

    container.documentChange = (): void => {
        container.documentEditor.focusIn();
    };
}

```
