GroupDocs Viewer Java ट्यूटोरियल: Word को HTML में बदलें और टिप्पणियों के साथ दस्तावेज़ रेंडर करें
परिचय
यदि आपको Word को HTML में बदलना है जबकि प्रत्येक समीक्षक की नोट, टिप्पणी या एनोटेशन को बनाए रखना है, तो आप सही जगह पर आए हैं। कई Java डेवलपर्स को दस्तावेज़ रूपांतरण के दौरान मूल फ़ाइल में एम्बेडेड मूल्यवान फीडबैक हट जाने की समस्या आती है। यह ट्यूटोरियल आपको GroupDocs Viewer for Java का उपयोग करके Word को HTML में बदलने और Word, Excel, PowerPoint, PDF और अधिक सहित विभिन्न दस्तावेज़ प्रकारों को बिना किसी टिप्पणी डेटा को खोए रेंडर करने के बारे में मार्गदर्शन करता है।
आप जानेंगे कि GroupDocs Viewer एक प्रोडक्शन‑रेडी विकल्प क्यों है, पर्यावरण कैसे सेटअप करें, आपको कौन सा कोड चाहिए, और बड़े फ़ाइलों के साथ भी प्रदर्शन तेज़ रखने के सिद्ध ट्रिक्स।

टिप्पणियों के साथ दस्तावेज़ रेंडर करें GroupDocs.Viewer for Java
आप इस ट्यूटोरियल में क्या सीखेंगे:
- GroupDocs Viewer की पूरी सेटअप और कॉन्फ़िगरेशन
- स्टेप‑बाय‑स्टेप Word को HTML में बदलना टिप्पणी संरक्षित के साथ
- सामान्य ट्रबलशूटिंग समाधान और बचने योग्य समस्याएँ
- वास्तविक दुनिया के इम्प्लीमेंटेशन पैटर्न और सर्वोत्तम प्रथाएँ
- प्रोडक्शन उपयोग के लिए प्रदर्शन अनुकूलन तकनीकें
त्वरित उत्तर
- क्या GroupDocs Viewer Word को HTML में बदल सकता है? हाँ—एक ही कोड लाइन में HTML रेंडरिंग और टिप्पणी समर्थन सक्षम करें।
- क्या टिप्पणियाँ HTML आउटपुट में रहती हैं? बिल्कुल—
setRenderComments(true)हर टिप्पणी और एनोटेशन को संरक्षित करता है। - कौन सा Java संस्करण आवश्यक है? JDK 8 या उससे ऊपर।
- क्या प्रोडक्शन के लिए लाइसेंस आवश्यक है? एक पूर्ण लाइसेंस वाटरमार्क हटाता है और सभी फीचर अनलॉक करता है।
- रेंडरिंग गति कैसे बढ़ाएँ? विशिष्ट पेज रेंडर करें, बाहरी संसाधन उपयोग करें, और JVM हीप साइज बढ़ाएँ।
“convert word to html” टिप्पणी के साथ क्या है?
“Convert Word to HTML” का अर्थ है Microsoft Word .docx फ़ाइल को वेब‑रेडी HTML दस्तावेज़ में बदलना, जबकि मूल लेआउट, स्टाइलिंग और सभी एम्बेडेड टिप्पणियों को बरकरार रखना। यह प्रक्रिया ब्राउज़र को दस्तावेज़ को बिल्कुल उसी तरह दिखाने देती है जैसा लेखक ने इच्छित किया था, समीक्षक की प्रतिक्रिया सहित।
Java के लिए GroupDocs Viewer क्यों चुनें?
कोड में डुबकी लगाने से पहले, चलिए देखते हैं कि Java‑आधारित दस्तावेज़ रेंडरिंग के लिए GroupDocs Viewer क्यों प्रमुख लाइब्रेरी है:
- 170+ समर्थित फ़ॉर्मेट – लाइब्रेरी DOCX से CAD फ़ाइलों तक सब कुछ संभालती है, जिससे आपके सभी रूपांतरण आवश्यकताओं के लिए एक ही डिपेंडेंसी मिलती है।
- कोई थर्ड‑पार्टी Office इंस्टॉलेशन नहीं – यह किसी भी OS पर काम करता है बिना Microsoft Office, LibreOffice या अन्य भारी रनटाइम्स की आवश्यकता के।
- फ़ॉर्मेटिंग और एनोटेशन संरक्षित – टिप्पणियाँ, फुटनोट और ट्रैक चेंजेज़ रूपांतरण के बाद भी बरकरार रहते हैं।
- तेज़, हल्का इंजन – सामान्य 100‑पेज दस्तावेज़ मानक 4‑कोर सर्वर पर 2 सेकंड से कम में रेंडर होते हैं।
- मजबूत डॉक्यूमेंटेशन और सक्रिय समुदाय – जब भी आपको समस्या आए, आप उदाहरण, फ़ोरम और त्वरित समर्थन पाएँगे।
इस दृष्टिकोण का उपयोग कब करें
- वेब‑आधारित दस्तावेज़ व्यूअर बनाना जो समीक्षक नोट्स दिखाने की आवश्यकता रखते हैं
- सहयोगी रिव्यू प्लेटफ़ॉर्म बनाना जहाँ फीडबैक दृश्यमान रहना चाहिए
- क़ानूनी पोर्टल में ऑनलाइन डिस्प्ले के लिए लेगेसी कॉन्ट्रैक्ट्स को बदलना
- ई‑लर्निंग समाधान विकसित करना जो अध्ययन सामग्री में प्रशिक्षक की टिप्पणियाँ एम्बेड करता है
पूर्वापेक्षाएँ और पर्यावरण सेटअप
आपको क्या चाहिए
- Java Development Kit (JDK) 8+ – वह रनटाइम जो आपके एप्लिकेशन को शक्ति देता है।
- Maven 3.6+ – डिपेंडेंसी मैनेजमेंट और प्रोजेक्ट बिल्ड के लिए।
- आपका पसंदीदा IDE – IntelliJ IDEA, Eclipse, या VS Code।
- टिप्पणियों वाले सैंपल दस्तावेज़ – DOCX, XLSX, PPTX फ़ाइलें जिनमें समीक्षक नोट्स हों।
अपने विकास पर्यावरण को सेटअप करना
चरण 1: Java इंस्टॉलेशन सत्यापित करें
एक टर्मिनल खोलें और चलाएँ:
java -version
चरण 2: Maven इंस्टॉलेशन जांचें
चलाएँ:
mvn -v
चरण 3: नया Maven प्रोजेक्ट बनाएं
एक स्केलेटन प्रोजेक्ट जनरेट करें:
mvn archetype:generate -DgroupId=com.example.viewer -DartifactId=viewer-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
viewer-demo फ़ोल्डर में नेविगेट करें और आप GroupDocs Viewer जोड़ने के लिए तैयार हैं।
GroupDocs.Viewer for Java सेटअप करना
डिपेंडेंसी जोड़ना
किसी भी GroupDocs Viewer Java ट्यूटोरियल में पहला कदम लाइब्रेरी को आपके प्रोजेक्ट में जोड़ना है। pom.xml फ़ाइल में यह कॉन्फ़िगरेशन जोड़ें:
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-viewer</artifactId>
<version>25.2</version>
</dependency>
प्रो टिप: हमेशा नवीनतम संस्करण के लिए GroupDocs रिलीज़ पेज देखें। लाइब्रेरी नियमित अपडेट और बग फिक्स के साथ सक्रिय रूप से मेंटेन की जाती है।
लाइसेंसिंग विकल्प समझना
GroupDocs विभिन्न प्रोजेक्ट आवश्यकताओं के लिए लचीला लाइसेंसिंग प्रदान करता है:
- Free Trial (सीखने के लिए परफेक्ट): 30‑दिन की इवैल्यूएशन पूरी फीचर एक्सेस और इवैल्यूएशन वाटरमार्क के साथ।
- Temporary License (डेवलपमेंट के लिए): वाटरमार्क के बिना विस्तारित इवैल्यूएशन; प्रूफ़‑ऑफ़‑कॉन्सेप्ट प्रोजेक्ट्स के लिए आदर्श। अनुरोध करें GroupDocs Temporary License Page पर।
- Full License (प्रोडक्शन रेडी): कोई सीमाएँ या वाटरमार्क नहीं, व्यावसायिक उपयोग की अनुमति। उपलब्ध है GroupDocs Purchase Page पर।
बेसिक इनिशियलाइज़ेशन पैटर्न
यह वह मूल पैटर्न है जिसे आप इस ट्यूटोरियल में उपयोग करेंगे:
try (Viewer viewer = new Viewer("input.docx")) {
// Rendering options will be set later
}
यह पैटर्न क्यों काम करता है:
- ऑटोमैटिक रिसोर्स मैनेजमेंट मेमोरी लीक को रोकता है।
- एक्सेप्शन हैंडलिंग सामान्य फ़ाइल‑एक्सेस समस्याओं को पकड़ती है।
- साफ, पठनीय कोड जो बड़े प्रोजेक्ट्स में बनाए रखने में आसान है।
कोर इम्प्लीमेंटेशन: टिप्पणियों के साथ दस्तावेज़ रेंडर करना
प्रक्रिया को समझना
जब आप GroupDocs Viewer के साथ दस्तावेज़ रेंडर करते हैं, लाइब्रेरी चार प्रमुख चरणों को निष्पादित करती है:
- डॉक्यूमेंट एनालिसिस – इनपुट फ़ाइल को पार्स करता है और आंतरिक प्रतिनिधित्व बनाता है।
- कॉमेंट एक्सट्रैक्शन – हर टिप्पणी, फुटनोट और एनोटेशन की पहचान करता है।
- HTML जेनरेशन – साफ, स्टैंडर्ड‑कम्प्लायंट HTML बनाता है जो मूल लेआउट को दर्शाता है।
- रिसोर्स हैंडलिंग – इमेज, CSS और फ़ॉन्ट्स को इनलाइन या एक्सटर्नल फ़ाइलों के रूप में बंडल करता है।
स्टेप‑बाय‑स्टेप इम्प्लीमेंटेशन
चरण 1: अपने फ़ाइल पाथ सेट करें
पाथ‑संबंधी त्रुटियों से बचने के लिए अपने इनपुट और आउटपुट लोकेशन को पहले व्यवस्थित करें:
Path inputPath = Paths.get("documents/sample-with-comments.docx");
Path outputDir = Paths.get("output/html");
Files.createDirectories(outputDir);
यह दृष्टिकोण क्यों?
- आधुनिक Java NIO.2
PathAPI का उपयोग करता है, जोjava.io.Fileसे अधिक भरोसेमंद है। - वर्णनात्मक वेरिएबल नाम डिबगिंग को आसान बनाते हैं।
- आउटपुट पैटर्न में
{0}प्लेसहोल्डर पेज नंबरों से स्वचालित रूप से बदल जाता है।
चरण 2: HTML रेंडरिंग विकल्प कॉन्फ़िगर करें
यहीं जादू होता है। हम GroupDocs को ठीक वही बताते हैं कि हम दस्तावेज़ को कैसे रेंडर करना चाहते हैं:
HtmlViewOptions कॉन्फ़िगर करता है कि दस्तावेज़ को HTML में कैसे रेंडर किया जाए, जिसमें रिसोर्स हैंडलिंग और टिप्पणी रेंडरिंग शामिल है।
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(outputDir);
viewOptions.setRenderComments(true); // Preserve every comment
viewOptions.setPageNumberPrefix("page_");
मुख्य कॉन्फ़िगरेशन विवरण:
forEmbeddedResources()CSS, इमेज और फ़ॉन्ट्स को सीधे HTML में एम्बेड करता है, जिससे आउटपुट पोर्टेबल बनता है।setRenderComments(true)वह एकल लाइन है जो सुनिश्चित करती है कि convert word to html सभी समीक्षक नोट्स को रखे।- वैकल्पिक
forExternalResources()आपको एसेट्स को अलग से स्टोर करने देता है यदि आप हल्की HTML फ़ाइल पसंद करते हैं।
चरण 3: रेंडरिंग निष्पादित करें
अब हम सब कुछ एक साथ लाते हैं:
Viewer मुख्य क्लास है जिसका उपयोग दस्तावेज़ लोड करने और रेंडरिंग ऑपरेशन्स करने के लिए किया जाता है।
try (Viewer viewer = new Viewer(inputPath.toFile())) {
viewer.view(viewOptions);
}
view कॉल Word फ़ाइल पढ़ता है, टिप्पणियों को एक्सट्रैक्ट करता है, HTML पेज बनाता है, और उन्हें output/html में लिखता है। प्रत्येक पेज page_1.html, page_2.html आदि के रूप में सहेजा जाता है।
पूर्ण कार्यशील उदाहरण
सभी हिस्सों को जोड़ने से आपको एक एकल, रन करने योग्य क्लास मिलती है जो Word दस्तावेज़ को HTML में बदलती है जबकि टिप्पणियों को बरकरार रखती है। (पूरा सोर्स कोड आधिकारिक GitHub रिपॉज़िटरी में उपलब्ध है।)
उन्नत कॉन्फ़िगरेशन और विकल्प
डायनामिक आउटपुट डायरेक्टरी सेट करना
बड़े एप्लिकेशन के लिए आप उपयोगकर्ता IDs या टाइमस्टैम्प के आधार पर आउटपुट डायरेक्टरी जनरेट करना चाह सकते हैं:
String userId = "12345";
Path dynamicOutput = Paths.get("output", userId, LocalDate.now().toString());
Files.createDirectories(dynamicOutput);
HtmlViewOptions dynamicOptions = HtmlViewOptions.forEmbeddedResources(dynamicOutput);
सामान्य समस्याएँ और ट्रबलशूटिंग
समस्या 1: “File Not Found” त्रुटियाँ
सुनिश्चित करें कि इनपुट पाथ एब्सोल्यूट या वर्किंग डायरेक्टरी के रिलेटिव है, और फ़ाइल परमिशन जांचें। Path ऑब्जेक्ट्स का उपयोग सामान्य स्ट्रिंग‑कंकैटनेशन त्रुटियों से बचाता है।
समस्या 2: आउटपुट में टिप्पणियाँ नहीं दिख रही हैं
दोबारा जांचें कि setRenderComments(true) viewer.view() से पहले कॉल किया गया है। साथ ही सुनिश्चित करें कि स्रोत दस्तावेज़ वास्तव में टिप्पणियाँ रखता है; आप उन्हें viewer.getDocumentInfo().getComments() के माध्यम से देख सकते हैं।
समस्या 3: बड़े दस्तावेज़ों के साथ मेमोरी समाप्ति त्रुटियाँ
GroupDocs Viewer डेटा को स्ट्रीम करता है, लेकिन अत्यधिक बड़े फ़ाइलें (> 500 पेज) अभी भी JVM हीप पर दबाव डाल सकती हैं। हीप साइज -Xmx4g से बढ़ाएँ या केवल आवश्यक पेज रेंडर करें।
समस्या 4: धीमी रेंडरिंग प्रदर्शन
viewer.view(pageRange, viewOptions) का उपयोग करके विशिष्ट पेज रेंज रेंडर करें। बाहरी रिसोर्स (forExternalResources()) भी HTML पेलोड साइज को कम करते हैं, जिससे ब्राउज़र रेंडरिंग तेज़ होती है।
वास्तविक‑दुनिया इम्प्लीमेंटेशन पैटर्न
पैटर्न 1: वेब एप्लिकेशन इंटीग्रेशन
रेंडरिंग लॉजिक को Spring Boot कंट्रोलर में इंटीग्रेट करें ताकि आवश्यकता पर HTML सर्व किया सके:
@RestController
@RequestMapping("/api/view")
public class DocumentController {
@GetMapping("/{id}")
public ResponseEntity<Resource> renderDocument(@PathVariable String id) throws IOException {
Path docPath = Paths.get("documents", id + ".docx");
Path outDir = Files.createTempDirectory("viewer");
HtmlViewOptions options = HtmlViewOptions.forEmbeddedResources(outDir);
options.setRenderComments(true);
try (Viewer viewer = new Viewer(docPath.toFile())) {
viewer.view(options);
}
// Return the first HTML page as a Resource
Path firstPage = outDir.resolve("page_1.html");
Resource resource = new UrlResource(firstPage.toUri());
return ResponseEntity.ok()
.contentType(MediaType.TEXT_HTML)
.body(resource);
}
}
पैटर्न 2: कई दस्तावेज़ों की बैच प्रोसेसिंग
जब आपको Word फ़ाइलों के पूरे फ़ोल्डर को बदलना हो, तो डायरेक्टरी में लूप करें और समान HtmlViewOptions इंस्टेंस को पुन: उपयोग करें ताकि ऑब्जेक्ट निर्माण ओवरहेड कम हो।
प्रदर्शन अनुकूलन और सर्वोत्तम प्रथाएँ
मेमोरी मैनेजमेंट टिप्स
- हमेशा try‑with‑resources का उपयोग
Viewerइंस्टेंस के लिए करें। - बड़े दस्तावेज़ों को बैच में प्रोसेस करें बजाय एक बार में सब कुछ मेमोरी में लोड करने के।
- JVM हीप उपयोग मॉनिटर करें VisualVM जैसे टूल्स से और आवश्यकता अनुसार
-Xmxसमायोजित करें। - उचित कैशिंग लागू करें अक्सर एक्सेस किए जाने वाले दस्तावेज़ों के लिए ताकि दोहराए गए रेंडरिंग से बचा जा सके।
रिसोर्स उपयोग दिशानिर्देश
छोटे एप्लिकेशन (< 100 दस्तावेज़/दिन) के लिए:
HtmlViewOptions options = HtmlViewOptions.forEmbeddedResources(Paths.get("output"));
options.setRenderComments(true);
उच्च‑वॉल्यूम एप्लिकेशन (1000+ दस्तावेज़/दिन) के लिए:
HtmlViewOptions options = HtmlViewOptions.forExternalResources(Paths.get("output"));
options.setRenderComments(true);
options.setCacheEnabled(true);
कैशिंग रणनीतियाँ
रेंडर किया गया HTML एक वितरित कैश (जैसे, Redis) में दस्तावेज़ हैश द्वारा कुंजीबद्ध करके स्टोर करें। जब अनुरोध आता है, पहले कैश जांचें; यदि हिट हो, तो रेंडरिंग इंजन को बायपास करके तुरंत कैश्ड HTML सर्व करें।
GroupDocs Viewer बनाम विकल्प कब उपयोग करें
GroupDocs Viewer के लिए परफेक्ट है
- डॉक्यूमेंट मैनेजमेंट सिस्टम – कई फ़ाइल प्रकारों को एनोटेशन के साथ दिखाने की आवश्यकता।
- सहयोगी रिव्यू प्लेटफ़ॉर्म – टिप्पणियों को सभी प्रतिभागियों के लिए दृश्यमान रहना चाहिए।
- शैक्षिक टूल्स – प्रशिक्षकों की नोट्स लेक्चर स्लाइड्स के साथ दिखाई देती हैं।
- क़ानूनी एप्लिकेशन – वकील की टिप्पणियों वाले कॉन्ट्रैक्ट्स को सटीक रेंडरिंग चाहिए।
विकल्प पर विचार कब करें
- साधारण PDF डिस्प्ले – नेटिव ब्राउज़र PDF व्यूअर पर्याप्त हो सकते हैं।
- बेसिक इमेज कन्वर्ज़न –
ImageIOया समान लाइब्रेरी हल्की हैं। - शुद्ध टेक्स्ट एक्सट्रैक्शन – Apache POI या iText अधिक उपयुक्त हो सकते हैं।
अक्सर पूछे जाने वाले प्रश्न
प्रश्न: क्या मैं दस्तावेज़ बिना टिप्पणियों के रेंडर कर सकता हूँ?
उत्तर: हाँ—सिर्फ setRenderComments(true) कॉल को हटाएँ या इसे false सेट करें।
प्रश्न: कौन से फ़ाइल फ़ॉर्मेट टिप्पणी रेंडरिंग का समर्थन करते हैं?
उत्तर: अधिकांश प्रमुख फ़ॉर्मेट—DOC/DOCX, XLS/XLSX, PPT/PPTX, PDF और कई अधिक। पूरी सूची के लिए आधिकारिक डॉक्यूमेंटेशन देखें।
प्रश्न: क्या मैं HTML आउटपुट स्टाइलिंग को कस्टमाइज़ कर सकता हूँ?
उत्तर: बिल्कुल। HtmlViewOptions.setEmbedResources(false) का उपयोग करके एक्सटर्नल CSS फ़ाइलें जनरेट करें, फिर रेंडरिंग के बाद अपनी स्टाइलशीट जोड़ें।
प्रश्न: पासवर्ड‑सुरक्षित दस्तावेज़ों को कैसे हैंडल करें?
उत्तर: पासवर्ड के साथ एक LoadOptions इंस्टेंस प्रदान करें:
LoadOptions आपको पासवर्ड जैसे दस्तावेज़ लोडिंग पैरामीटर निर्दिष्ट करने की अनुमति देता है।
LoadOptions loadOptions = new LoadOptions("myPassword");
try (Viewer viewer = new Viewer(inputPath.toFile(), loadOptions)) {
viewer.view(viewOptions);
}
प्रश्न: क्या केवल विशिष्ट पेज रेंडर करना संभव है?
उत्तर: हाँ—view मेथड का ओवरलोडेड संस्करण उपयोग करें जो PageNumber कलेक्शन स्वीकार करता है:
PageNumber एक विशिष्ट पेज इंडेक्स को दर्शाता है जिसका उपयोग पेजों के उपसमुच्चय को रेंडर करने में किया जाता है।
viewer.view(new int[]{1, 3, 5}, viewOptions);
प्रश्न: बड़े दस्तावेज़ों के लिए रेंडरिंग धीमी क्यों होती है?
उत्तर: बड़े फ़ाइलों को अधिक प्रोसेसिंग समय चाहिए। गति बढ़ाने के लिए केवल आवश्यक पेज रेंडर करें, बाहरी रिसोर्स उपयोग करें, JVM हीप बढ़ाएँ, और असिंक्रोनस प्रोसेसिंग सक्षम करें।
प्रश्न: मैं रेंडरिंग प्रोग्रेस कैसे मॉनिटर कर सकता हूँ?
उत्तर: जबकि GroupDocs Viewer में बिल्ट‑इन कॉलबैक नहीं है, आप viewer.view() से पहले और बाद में System.nanoTime() से ऑपरेशन का समय ले सकते हैं और अवधि लॉग कर सकते हैं।
प्रश्न: यदि स्रोत दस्तावेज़ भ्रष्ट है तो क्या होता है?
उत्तर: लाइब्रेरी ViewerException थ्रो करती है। कॉल को try‑catch ब्लॉक में रैप करें और ग्रेसफुल डिग्रेडेशन के लिए एरर लॉग करें।
प्रश्न: क्या मैं GroupDocs Viewer को व्यावसायिक एप्लिकेशन में उपयोग कर सकता हूँ?
उत्तर: हाँ, लेकिन एक व्यावसायिक लाइसेंस आवश्यक है। फ्री ट्रायल में वाटरमार्क होते हैं जिन्हें प्रोडक्शन उपयोग के लिए हटाना आवश्यक है।
प्रश्न: क्या कोई उपयोग सीमा है?
उत्तर: लाइब्रेरी स्वयं कोई सीमा नहीं लगाती, हालांकि आपका लाइसेंस एग्रीमेंट उपयोग कैप्स निर्धारित कर सकता है। विवरण के लिए अपना कॉन्ट्रैक्ट देखें।
प्रश्न: क्या मैं GroupDocs Viewer शामिल करने वाले एप्लिकेशन को पुनः वितरित कर सकता हूँ?
उत्तर: आप अपना एप्लिकेशन वितरित कर सकते हैं, लेकिन GroupDocs लाइब्रेरी बाइनरीज़ को पुनः वितरित नहीं कर सकते। अनुपालन के लिए लाइसेंस शर्तें देखें।
अगले कदम और उन्नत विषय
अब आपके पास convert word to html के साथ टिप्पणियों को संरक्षित करने की ठोस नींव है। यहाँ कुछ दिशा‑निर्देश हैं जिससे आप अपनी विशेषज्ञता को गहरा कर सकते हैं:
- वॉटरमार्किंग – ब्रांडिंग या गोपनीयता के लिए रेंडर किए गए पेजों पर कस्टम वॉटरमार्क जोड़ें।
- मेटाडेटा एक्सट्रैक्शन –
viewer.getDocumentInfo()के माध्यम से लेखक, निर्माण तिथि और पेज काउंट प्राप्त करें। - कस्टम व्यूअर्स – PDFs, स्प्रेडशीट्स, या प्रेजेंटेशन के लिए विशेष व्यूअर्स बनाएं जो टिप्पणियों को अलग तरीके से छुपाते या हाइलाइट करते हैं।
- क्लाउड स्टोरेज इंटीग्रेशन – फ़ाइलों को सीधे AWS S3, Azure Blob, या Google Drive से रेंडर करें बिना स्थानीय रूप से डाउनलोड किए।
अनुशंसित लर्निंग पाथ
- विभिन्न फ़ाइल प्रकारों के साथ प्रयोग करें – Excel, PowerPoint, और PDF फ़ाइलों को आज़माएँ ताकि देखें कि विभिन्न फ़ॉर्मेट में टिप्पणियों को कैसे संभाला जाता है।
- एक सरल वेब व्यूअर बनाएं – एक न्यूनतम HTML पेज बनाएं जो जनरेटेड HTML को
<iframe>या AJAX के माध्यम से लोड करता है। - GroupDocs इकोसिस्टम का अन्वेषण करें – एन्ड‑टू‑एन्ड डॉक्यूमेंट वर्कफ़्लो के लिए GroupDocs Annotation, Comparison, और Signature देखें।
- समुदाय में शामिल हों – टिप्स, सैंपल प्रोजेक्ट्स, और सपोर्ट के लिए GroupDocs फ़ोरम में भाग लें।
मदद और समर्थन प्राप्त करना
आधिकारिक संसाधन
समुदाय संसाधन
- Stack Overflow (tag:
groupdocs-viewer) - Reddit programming communities
- Java developer Discord servers
अंतिम अपडेट: 2026-05-21
परीक्षित संस्करण: GroupDocs.Viewer 25.2 for Java
लेखक: GroupDocs
java -version
javac -version
mvn -version
mvn archetype:generate -DgroupId=com.example.documentviewer -DartifactId=groupdocs-viewer-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/viewer/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-viewer</artifactId>
<version>25.2</version>
</dependency>
</dependencies>
import com.groupdocs.viewer.Viewer;
// The try-with-resources pattern ensures proper cleanup
try (Viewer viewer = new Viewer("path/to/your/document.docx")) {
// All rendering operations happen here
// Resources are automatically closed when done
} catch (Exception e) {
System.err.println("Error rendering document: " + e.getMessage());
e.printStackTrace();
}
import java.nio.file.Path;
import java.nio.file.Paths;
// Create a descriptive output directory
Path outputDirectory = Paths.get("rendered-documents");
Path pageFilePathFormat = outputDirectory.resolve("page_{0}.html");
import com.groupdocs.viewer.options.HtmlViewOptions;
// Create HTML options with embedded resources
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(pageFilePathFormat);
// The crucial setting – enable comment rendering!
viewOptions.setRenderComments(true);
import com.groupdocs.viewer.Viewer;
try (Viewer viewer = new Viewer("path/to/your/document.docx")) {
// Create output directory if it doesn't exist
if (!outputDirectory.toFile().exists()) {
outputDirectory.toFile().mkdirs();
}
// Perform the actual rendering
viewer.view(viewOptions);
System.out.println("Document rendered successfully!");
System.out.println("Output location: " + outputDirectory.toAbsolutePath());
} catch (Exception e) {
System.err.println("Rendering failed: " + e.getMessage());
e.printStackTrace();
}
package com.example.documentviewer;
import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.HtmlViewOptions;
import java.nio.file.Path;
import java.nio.file.Paths;
public class DocumentRenderer {
public static void main(String[] args) {
renderDocumentWithComments("sample-document.docx", "output");
}
public static void renderDocumentWithComments(String inputFile, String outputDir) {
// Set up paths
Path outputDirectory = Paths.get(outputDir);
Path pageFilePathFormat = outputDirectory.resolve("page_{0}.html");
// Configure rendering options
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(pageFilePathFormat);
viewOptions.setRenderComments(true);
// Render the document
try (Viewer viewer = new Viewer(inputFile)) {
// Ensure output directory exists
outputDirectory.toFile().mkdirs();
// Execute rendering
viewer.view(viewOptions);
System.out.println("✓ Document rendered with comments preserved");
System.out.println("📂 Output directory: " + outputDirectory.toAbsolutePath());
} catch (Exception e) {
System.err.println("❌ Rendering failed: " + e.getMessage());
e.printStackTrace();
}
}
}
import java.nio.file.Path;
import java.nio.file.Paths;
public class PathManager {
/**
* Creates a structured output path based on document name and timestamp
*/
public static Path getOutputDirectoryPath(String documentName) {
String timestamp = String.valueOf(System.currentTimeMillis());
String cleanDocName = documentName.replaceAll("[^a-zA-Z0-9]", "_");
return Paths.get("rendered-docs")
.resolve(cleanDocName)
.resolve(timestamp);
}
/**
* Simple output directory for basic use cases
*/
public static Path getSimpleOutputPath(String folderName) {
return Paths.get("output").resolve(folderName);
}
}
// Always check if file exists before processing
Path inputPath = Paths.get("your-document.docx");
if (!inputPath.toFile().exists()) {
throw new IllegalArgumentException("Input file not found: " + inputPath.toAbsolutePath());
}
// Check if file is readable
if (!inputPath.toFile().canRead()) {
throw new IllegalArgumentException("Cannot read input file: " + inputPath.toAbsolutePath());
}
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(pageFilePathFormat);
// This line is crucial – don't forget it!
viewOptions.setRenderComments(true);
// For debugging, you can verify the setting:
System.out.println("Comments enabled: " + viewOptions.isRenderComments());
// Increase JVM heap size when running
// java -Xmx2g -Xms1g YourApplication
// Or process documents page by page for very large files
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(pageFilePathFormat);
viewOptions.setRenderComments(true);
// Render only specific pages if needed
viewer.view(viewOptions, 1, 2, 3); // Renders only pages 1, 2, and 3
// Use external resources for faster processing of multiple pages
HtmlViewOptions viewOptions = HtmlViewOptions.forExternalResources(
pageFilePathFormat,
"resources/page_{0}/",
"resources/page_{0}/{0}"
);
// Enable caching if processing the same document multiple times
// (Note: Implement caching at application level)
@RestController
@RequestMapping("/api/documents")
public class DocumentController {
@PostMapping("/render")
public ResponseEntity<String> renderDocument(
@RequestParam("file") MultipartFile file) {
try {
// Save uploaded file temporarily
Path tempFile = Files.createTempFile("upload", ".tmp");
file.transferTo(tempFile.toFile());
// Render with comments
String outputDir = renderDocumentWithComments(
tempFile.toString(),
"web-output"
);
return ResponseEntity.ok("Document rendered: " + outputDir);
} catch (Exception e) {
return ResponseEntity.badRequest()
.body("Rendering failed: " + e.getMessage());
}
}
}
public class BatchDocumentProcessor {
public void processFolderWithComments(String inputFolder) {
File folder = new File(inputFolder);
File[] files = folder.listFiles((dir, name) ->
name.toLowerCase().endsWith(".docx") ||
name.toLowerCase().endsWith(".xlsx") ||
name.toLowerCase().endsWith(".pptx")
);
if (files == null) return;
for (File file : files) {
try {
String outputDir = file.getName().replace(".", "_") + "_output";
renderDocumentWithComments(file.getAbsolutePath(), outputDir);
System.out.println("✓ Processed: " + file.getName());
} catch (Exception e) {
System.err.println("❌ Failed to process " + file.getName() + ": " + e.getMessage());
}
}
}
}
// Simple approach works fine
try (Viewer viewer = new Viewer(documentPath)) {
viewer.view(viewOptions);
}
public class DocumentRenderingService {
private final ExecutorService executorService =
Executors.newFixedThreadPool(4); // Limit concurrent renderings
public CompletableFuture<String> renderAsync(String documentPath) {
return CompletableFuture.supplyAsync(() -> {
try (Viewer viewer = new Viewer(documentPath)) {
// Rendering logic here
return "success";
} catch (Exception e) {
throw new RuntimeException(e);
}
}, executorService);
}
}
public class CachedDocumentRenderer {
private final Map<String, String> renderCache = new ConcurrentHashMap<>();
public String renderWithCaching(String documentPath) {
String cacheKey = generateCacheKey(documentPath);
return renderCache.computeIfAbsent(cacheKey, key -> {
// Only render if not already cached
return performActualRendering(documentPath);
});
}
private String generateCacheKey(String documentPath) {
// Include file modification time in cache key
File file = new File(documentPath);
return documentPath + "_" + file.lastModified();
}
}
LoadOptions loadOptions = new LoadOptions();
loadOptions.setPassword("your-password");
try (Viewer viewer = new Viewer("protected-doc.docx", loadOptions)) {
// Render as usual
}
viewer.view(viewOptions, 1, 3, 5); // Renders only pages 1, 3, and 5
System.out.println("Starting render for: " + documentName);
long startTime = System.currentTimeMillis();
viewer.view(viewOptions);
long endTime = System.currentTimeMillis();
System.out.println("Rendering completed in: " + (endTime - startTime) + "ms");
try (Viewer viewer = new Viewer(documentPath)) {
viewer.view(viewOptions);
} catch (CorruptOrDamagedFileException e) {
System.err.println("Document is corrupted: " + e.getMessage());
} catch (Exception e) {
System.err.println("General error: " + e.getMessage());
}