GroupDocs.Editor के साथ DOCX को संपादित करने और फ़ॉर्मेट बदलने का तरीका

अपने .NET पर्यावरण में GroupDocs.Editor .NET का उपयोग करके Word दस्तावेज़ों को आसानी से प्रबंधित और परिवर्तित करें। इस ट्यूटोरियल में आप how to edit docx फ़ाइलों को कैसे संपादित करें, उन्हें RTF, DOCM और साधारण टेक्स्ट जैसे फ़ॉर्मेट में बदलें, और अधिकतम उत्पादकता के लिए अपने दस्तावेज़ वर्कफ़्लो को स्वचालित करना सीखेंगे।

त्वरित उत्तर

  • What library is required? GroupDocs.Editor for .NET (20.10+).
  • Can I convert a DOCX to RTF? Yes – use WordProcessingSaveOptions with WordProcessingFormats.Rtf.
  • Is saving as TXT supported? Absolutely, via TextSaveOptions.
  • Do I need a license? A trial works for development; a license unlocks all features.
  • How to handle many files? Combine the code with async/await or Parallel.ForEach for batch processing.

GroupDocs.Editor के साथ “how to edit docx” क्या है?

GroupDocs.Editor एक DOCX लोड करता है, उसकी सामग्री को संपादन योग्य HTML के रूप में प्रस्तुत करता है, आपको प्रोग्रामेटिकली उस HTML को संशोधित करने देता है, और फिर परिणाम को किसी भी समर्थित फ़ॉर्मेट में वापस सहेजता है। यह तरीका Office इंटरऑप की आवश्यकता को समाप्त करता है और किसी भी सर्वर‑साइड .NET प्लेटफ़ॉर्म पर काम करता है।

दस्तावेज़ वर्कफ़्लो ऑटोमेशन के लिए GroupDocs.Editor का उपयोग क्यों करें?

  • Server‑side only – no Office installation required.
  • Multiple output formats – RTF, DOCM, TXT, HTML, PDF, etc.
  • High performance – lightweight API designed for batch scenarios.
  • Full control – edit, replace, or inject HTML fragments before saving.

पूर्वापेक्षाएँ

  • GroupDocs.Editor लाइब्रेरी (Version 20.10 या बाद का)
  • .NET Framework 4.7.2 + or .NET 5/6
  • Visual Studio (any recent edition)
  • बेसिक C# ज्ञान और फ़ाइल I/O से परिचितता

GroupDocs.Editor स्थापित करना

आप पैकेज को .NET CLI, पैकेज मैनेजर कंसोल, या NuGet UI के माध्यम से जोड़ सकते हैं।

dotnet add package GroupDocs.Editor
Install-Package GroupDocs.Editor

लाइसेंस प्राप्ति

पहले एक मुफ्त ट्रायल से शुरू करें या अस्थायी लाइसेंस कुंजी का अनुरोध करें। उत्पादन उपयोग के लिए, अनलिमिटेड प्रोसेसिंग को अनलॉक करने हेतु लाइसेंस खरीदें।

DOCX दस्तावेज़ को लोड और संपादित करने का तरीका

पहले, एडिटर को अपनी स्रोत फ़ाइल की ओर इंगित करें, फिर संपादन योग्य HTML प्राप्त करें, आवश्यक परिवर्तन करें, और अंत में संशोधित मार्कअप से नया EditableDocument बनाएं।

using (Editor editor = new Editor("YOUR_DOCUMENT_DIRECTORY/sample.docx", new Options.WordProcessingLoadOptions()))
{
    // Your document manipulation code here
}

स्टेप‑बाय‑स्टेप कोड वॉकथ्रू

  1. Define the input file path
string inputFilePath = "YOUR_DOCUMENT_DIRECTORY/sample.docx";
  1. Create the Editor instance
using GroupDocs.Editor;
using GroupDocs.Editor.Options;

Editor editor = new Editor(inputFilePath, new Options.WordProcessingLoadOptions());
  1. Edit the document’s HTML
EditableDocument defaultWordProcessingDoc = editor.Edit();
string allEmbeddedInsideString = defaultWordProcessingDoc.GetEmbeddedHtml();
string allEmbeddedInsideStringEdited = allEmbeddedInsideString.Replace("Subtitle", "Edited subtitle");
  1. Create a new EditableDocument from the edited HTML
EditableDocument editedDoc = EditableDocument.FromMarkup(allEmbeddedInsideStringEdited, null);
  1. Dispose of temporary objects
editedDoc.Dispose();
defaultWordProcessingDoc.Dispose();
editor.Dispose();

Word को RTF में बदलने का तरीका

उचित सहेजने विकल्पों के साथ संपादित दस्तावेज़ को RTF के रूप में सहेजना सरल है।

string outputRtfPath = Path.Combine("YOUR_OUTPUT_DIRECTORY", "editedDoc.rtf");
WordProcessingSaveOptions rtfSaveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Rtf);
using (Editor editor = new Editor(inputFilePath, new Options.WordProcessingLoadOptions()))
{
    editor.Save(editedDoc, outputRtfPath, rtfSaveOptions);
}
editor.Dispose();

स्ट्रीम का उपयोग करके DOCX को DOCM के रूप में सहेजने का तरीका

जब आपको मैक्रो‑सक्षम DOCM फ़ॉर्मेट चाहिए, तो आप सीधे FileStream में लिख सकते हैं।

string outputDocmPath = Path.Combine("YOUR_OUTPUT_DIRECTORY", "editedDoc.docm");
WordProcessingSaveOptions docmSaveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Docm);
using (Editor editor = new Editor(inputFilePath, new Options.WordProcessingLoadOptions()))
{
    using (FileStream outputStream = File.Create(outputDocmPath))
    {
        editor.Save(editedDoc, outputStream, docmSaveOptions);
    }
}
editor.Dispose();

DOCX को TXT (सादा टेक्स्ट) में बदलने का तरीका

सादा टेक्स्ट निकासी इंडेक्सिंग, खोज, या ईमेल नोटिफिकेशन के लिए उपयोगी है।

string outputTxtPath = Path.Combine("YOUR_OUTPUT_DIRECTORY", "editedDoc.txt");
TextSaveOptions textSaveOptions = new TextSaveOptions()
{
    Encoding = Encoding.UTF8,
    PreserveTableLayout = true
};
using (Editor editor = new Editor(inputFilePath, new Options.WordProcessingLoadOptions()))
{
    editor.Save(editedDoc, outputTxtPath, textSaveOptions);
}
editor.Dispose();

सामान्य उपयोग केस और वास्तविक‑दुनिया के परिदृश्य

  • Automated Report Generation: Convert analytical Word reports to TXT for email distribution.
  • Collaborative Editing Platforms: Let users edit HTML fragments and store the result as DOCM or RTF.
  • Document Archiving: Migrate legacy DOCX files to DOCM for macro support while preserving content.
  • Web Services: Stream DOCX → PDF/RTF conversions on the fly without temporary files.

Word दस्तावेज़ों के बैच प्रोसेसिंग के लिए प्रदर्शन टिप्स

  • Dispose promptly: Always call Dispose() on Editor and document objects.
  • Load wisely: Choose the most specific LoadOptions to avoid unnecessary parsing.
  • Parallelize safely: Use Parallel.ForEach with separate Editor instances per thread.
  • Avoid large in‑memory strings: When processing huge documents, work with streams instead of full HTML strings.

अक्सर पूछे जाने वाले प्रश्न

Q: Can I edit a password‑protected DOCX?
A: Yes. Supply the password via WordProcessingLoadOptions.Password when creating the Editor.

Q: Is it possible to convert many files in one run?
A: Absolutely. Wrap the single‑file logic in a loop or use Parallel.ForEach for concurrent processing.

Q: Does GroupDocs.Editor support .NET Core?
A: The library works with .NET 5, .NET 6, and .NET Core 3.1 as well as the full .NET Framework.

Q: What happens to macros when I save as DOCM?
A: Macros are preserved when you use the Docm save format; they are stripped for RTF/TXT.

Q: How can I troubleshoot “OutOfMemoryException” during large batch jobs?
A: Process files in smaller batches, dispose objects immediately, and consider increasing the application’s memory limit.

निष्कर्ष

अब आपके पास how to edit docx फ़ाइलों को GroupDocs.Editor .NET का उपयोग करके RTF, DOCM, या साधारण टेक्स्ट में बदलने के लिए एक पूर्ण, प्रोडक्शन‑रेडी वर्कफ़्लो है। ऊपर दिए गए चरणों का पालन करके आप दस्तावेज़ वर्कफ़्लो को स्वचालित कर सकते हैं, बैच प्रोसेसिंग को संभाल सकते हैं, और किसी भी .NET एप्लिकेशन में सहज फ़ॉर्मेट कन्वर्ज़न को एकीकृत कर सकते हैं।


अंतिम अपडेट: 2026-04-07
परीक्षित संस्करण: GroupDocs.Editor 20.10 (latest at time of writing)
लेखक: GroupDocs