# Edit Word Documents in Node.js and Java This guide demonstrates how to edit DOC, DOT, DOCX, DOCM, DOTX, ODT, RTF documents with font extraction, different pagination modes, and many other powerful features of GroupDocs.Editor for Node.js and Java. ## How to edit a Word document? GroupDocs.Editor for Node.js and Java supports editing WordProcessing formats such as DOC, DOCX, DOT, DOCM, DOTX, ODT, and RTF. It allows two processing modes: - **float** (default) - **paged** (also known as **paginal**) In float mode, the document appears as a single page when loaded into the WYSIWYG editor. In paged mode, the document is displayed with its original page breaks, similar to Microsoft Word. ### Loading WordProcessing documents Start by loading the document into the `Editor` class. Here’s an example of loading a password-protected DOCX file: ```javascript const groupdocs = require('groupdocs-editor'); const Editor = groupdocs.Editor; const WordProcessingLoadOptions = groupdocs.options.WordProcessingLoadOptions; // Load options for a password-protected document const loadOptions = new WordProcessingLoadOptions(); loadOptions.password = "some_password_to_open_document"; // Load the document into the Editor const inputPath = "C://input_path/document.docx"; const editor = new Editor(inputPath, loadOptions); --- ## How to edit a Word document? GroupDocs.Editor for Node.js supports editing WordProcessing formats such as DOC, DOCX, DOT, DOCM, DOTX, ODT, and RTF. It allows two processing modes: - **float** (default) - **paged** (also known as **paginal**) In float mode, the document appears as a single page when loaded into the WYSIWYG editor. In paged mode, the document is displayed with its original page breaks, similar to Microsoft Word. ### Loading WordProcessing documents Start by loading the document into the `Editor` class. Here’s an example of loading a password-protected DOCX file: ```javascript const groupdocs = require('groupdocs-editor'); const Editor = groupdocs.Editor; const WordProcessingLoadOptions = groupdocs.options.WordProcessingLoadOptions; // Load options for a password-protected document const loadOptions = new WordProcessingLoadOptions(); loadOptions.password = "some_password_to_open_document"; // Load the document into the Editor const inputPath = "C://input_path/document.docx"; const editor = new Editor(inputPath, loadOptions); ``` If the document is unprotected, the password will be ignored. If the document is protected but no password is provided, an error will be thrown during editing. ### Editing WordProcessing documents Once the document is loaded, you can edit it by creating `WordProcessingEditOptions`: ```javascript const WordProcessingEditOptions = groupdocs.options.WordProcessingEditOptions; let editOptions = new WordProcessingEditOptions(); editOptions.fontExtraction = groupdocs.options.FontExtractionOptions.ExtractEmbeddedWithoutSystem; editOptions.enableLanguageInformation = true; editOptions.enablePagination = true; ``` Explanation: - `fontExtraction`: Extracts fonts used in the document. - `enableLanguageInformation`: Enables language information extraction for spell-checking. - `enablePagination`: Switches from the default float mode to paged mode. Next, edit the document using the prepared options: ```javascript let editableDocument = editor.edit(editOptions); ``` To extract the HTML markup and resources separately: ```javascript let originalContent = editableDocument.getContent(); let allResources = editableDocument.getAllResources(); ``` ### Modifying document content After editing the document in the WYSIWYG-editor on the client side, pass the modified content back to the server: ```javascript let editedContent = originalContent.replace("document", "edited document"); let updatedDocument = groupdocs.EditableDocument.fromMarkup(editedContent, allResources); ``` ### Saving the Word document after editing To save the edited document, you first need to create `WordProcessingSaveOptions`: ```javascript const WordProcessingSaveOptions = groupdocs.options.WordProcessingSaveOptions; let saveOptions = new WordProcessingSaveOptions(groupdocs.formats.WordProcessingFormats.Docm); saveOptions.password = "password"; saveOptions.enablePagination = true; saveOptions.locale = "en-US"; saveOptions.optimizeMemoryUsage = true; saveOptions.protection = new groupdocs.options.WordProcessingProtection( groupdocs.options.WordProcessingProtectionType.ReadOnly, "write_password" ); ``` Explanation: 1. `WordProcessingFormats.Docm`: Sets the format to DOCM. 2. `password`: Encrypts the document with a password. 3. `enablePagination`: Preserves pagination in the saved document. 4. `locale`: Sets the locale. 5. `optimizeMemoryUsage`: Optimizes memory for large documents. 6. `protection`: Adds write protection to the document. Finally, save the document: ```javascript let outputPath = "C://output_path/edited_document.docm"; editor.save(updatedDocument, outputPath, saveOptions); ``` ## Contents - [Adding class name to input controls](https://docs.groupdocs.com/editor/nodejs-java/adding-class-name-to-input-controls.md) - [Document protection](https://docs.groupdocs.com/editor/nodejs-java/document-protection.md) - [Enabling language information](https://docs.groupdocs.com/editor/nodejs-java/enabling-language-information.md) - [Float and paginal modes](https://docs.groupdocs.com/editor/nodejs-java/float-and-paginal-modes.md) - [Font extraction options](https://docs.groupdocs.com/editor/nodejs-java/font-extraction-options.md) - [Font embedding options](https://docs.groupdocs.com/editor/nodejs-java/font-embedding-options.md) - [Locales for Output Document](https://docs.groupdocs.com/editor/nodejs-java/locales-for-output-document.md) - [Memory Optimization Option](https://docs.groupdocs.com/editor/nodejs-java/memory-optimization-option.md) - [Export Styles During Document Editing](https://docs.groupdocs.com/editor/nodejs-java/styles-export.md) - [Enabling Inline CSS Styles](https://docs.groupdocs.com/editor/nodejs-java/inline-styles.md) - [Output Format and Password](https://docs.groupdocs.com/editor/nodejs-java/output-format-and-password.md) - [Generating Page Preview for WordProcessing Documents](https://docs.groupdocs.com/editor/nodejs-java/generating-page-preview.md)