GroupDocs.Parser for Java का उपयोग करके Word से छवियों को निकालें
Extracting images from Word files manually is time‑consuming and error‑prone. In this tutorial you’ll discover how to extract images from word documents automatically with GroupDocs.Parser for Java, and then save word images png for downstream processing. You’ll get a clear overview of why the library is fast, how to set it up, and best‑practice tips that let you embed image extraction into any Java application.
त्वरित उत्तर
- लाइब्रेरी क्या करती है? यह Word, PDF, और कई अन्य फ़ॉर्मेट को पार्स करती है ताकि टेक्स्ट, टेबल और इमेजेज़ को एक्सपोज़ किया जा सके।
- कोड की कितनी लाइन्स हैं? लगभग 30 लाइन्स Java की, साथ में कुछ कॉन्फ़िगरेशन लाइन्स।
- क्या मुझे लाइसेंस चाहिए? विकास के लिए एक फ्री ट्रायल काम करता है; प्रोडक्शन के लिए पूर्ण लाइसेंस आवश्यक है।
- क्या मैं एम्बेडेड इमेजेज़ निकाल सकता हूँ? हाँ –
getImages()मेथड हर एम्बेडेड इमेज को रिटर्न करता है। - समर्थित आउटपुट फ़ॉर्मेट? डिफ़ॉल्ट PNG है, लेकिन अन्य फ़ॉर्मेट
ImageFormatके माध्यम से उपलब्ध हैं।
“extract images from word” क्या है?
Extract images from word refers to programmatically retrieving all picture files embedded in a Microsoft Word document. GroupDocs.Parser reads the binary structure of a DOCX or DOC file and surfaces each image as a PageImageArea object, allowing you to pull out every picture without opening the document in Microsoft Word. This approach eliminates manual copy‑paste, reduces human error, and scales to thousands of files in batch jobs.
GroupDocs.Parser for Java का उपयोग क्यों करें?
You can extract images from word documents with speed, reliability, and cross‑platform flexibility. GroupDocs.Parser processes a 200‑page DOCX in under 2 seconds on a standard 2 CPU server, and it works on Windows, Linux, and macOS without requiring Microsoft Office. The library also tolerates corrupted files, returning whatever images are still accessible, which makes it ideal for large‑scale migration projects.
पूर्वापेक्षाएँ
- GroupDocs.Parser for Java (संस्करण 25.5 या नया)
- JDK 8+ आपके विकास मशीन पर स्थापित
- IntelliJ IDEA, Eclipse, या NetBeans जैसे IDE कोड को एडिट और रन करने के लिए
GroupDocs.Parser for Java सेटअप करना
Add the library to your Maven project:
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/parser/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-parser</artifactId>
<version>25.5</version>
</dependency>
</dependencies>
वैकल्पिक रूप से, नवीनतम संस्करण सीधे GroupDocs.Parser for Java releases से डाउनलोड करें।
लाइसेंस प्राप्त करने के चरण
- Free trial: क्षमताओं को एक्सप्लोर करने के लिए फ्री ट्रायल से शुरू करें।
- Temporary license: यदि आवश्यक हो तो विस्तारित परीक्षण के लिए टेम्पररी लाइसेंस प्राप्त करें।
- Purchase: प्रोडक्शन डिप्लॉयमेंट के लिए पूर्ण लाइसेंस प्राप्त करें।
कार्यान्वयन गाइड
Below is the complete, ready‑to‑run Java code that extracts images from word documents and saves them as PNG files.
चरण 1: पार्सर को इनिशियलाइज़ करें
Parser क्लास दस्तावेज़ पढ़ने का एंट्री पॉइंट है। यह फ़ाइल को मेमोरी में लोड करता है और एक्सट्रैक्शन के लिए सभी कंटेंट स्ट्रीम्स तैयार करता है।
// Initialize the Parser with the document path.
try (Parser parser = new Parser(documentPath)) {
// Proceed with image extraction...
}
चरण 2: छवियों को निकालें
PageImageArea ऑब्जेक्ट्स दस्तावेज़ में मिलने वाली प्रत्येक तस्वीर को दर्शाते हैं, चाहे इमेज इनलाइन हो, फ्लोटिंग हो, या शैप का हिस्सा हो।
// Extract images from the document.
Iterable<PageImageArea> images = parser.getImages();
चरण 3: इमेज विकल्प कॉन्फ़िगर करें
ImageOptions आपको प्रत्येक तस्वीर को सहेजने से पहले आउटपुट फ़ॉर्मेट, रिज़ॉल्यूशन, और अन्य रेंडरिंग सेटिंग्स निर्दिष्ट करने की अनुमति देता है।
// Set options to save images in PNG format.
ImageOptions options = new ImageOptions(ImageFormat.Png);
चरण 4: प्रत्येक इमेज को सहेजें
ImageFormat एन्नुम आउटपुट इमेज फ़ॉर्मेट को परिभाषित करता है जैसे PNG, JPEG, या BMP।save मेथड बाइनरी इमेज डेटा को डिस्क पर फ़ाइल में लिखता है। ImageFormat.Png पास करके आप save word images png आवश्यकता को पूरा करते हैं।
int imageNumber = 0;
for (PageImageArea image : images) {
String outputPath = YOUR_OUTPUT_DIRECTORY + "/" + imageNumber + ".png";
image.save(outputPath, options);
imageNumber++;
}
चरण 5: पाथ के लिए हेल्पर मेथड्स परिभाषित करें
यूटिलिटी मेथड्स पाथ हैंडलिंग को सरल बनाते हैं और मुख्य एक्सट्रैक्शन लॉजिक को साफ़ और मेंटेनेबल रखते हैं।
public static String getDocumentDirectory() {
return YOUR_DOCUMENT_DIRECTORY;
}
public static String getOutputDirectory() {
return YOUR_OUTPUT_DIRECTORY;
}
YOUR_DOCUMENT_DIRECTORY और YOUR_OUTPUT_DIRECTORY को उन वास्तविक फ़ाइल सिस्टम लोकेशन से बदलें जिन्हें आप उपयोग करना चाहते हैं।
docx से एम्बेडेड इमेजेज़ कैसे निकालें?
The getImages() method returns a collection of PageImageArea objects representing each embedded image.
Load the DOCX with new Parser("input.docx") and call parser.getImages() – the method automatically returns every embedded image, including inline pictures, floating shapes, and VML drawings. No additional API calls are required, so you can iterate over the returned collection and process each PageImageArea directly.
docx से इमेजेज़ निकालें और PNG के रूप में सहेजें कैसे?
Create an ImageOptions instance, set options.setImageFormat(ImageFormat.Png), and pass it to image.save(outputPath, options). This configuration ensures each extracted picture is written as a PNG file, meeting the save word images png goal while preserving original resolution and color depth.
व्यावहारिक अनुप्रयोग
- Content management: लेगेसी Word फ़ाइलों से इमेजेज़ निकालकर डिजिटल एसेट लाइब्रेरी में जोड़ें।
- Data migration: एम्बेडेड ग्राफ़िक्स को नई CMS में मैन्युअल कॉपी‑पेस्ट के बिना स्थानांतरित करें।
- Document archiving: इमेजेज़ को अलग से स्टोर करके आर्काइव साइज कम करें और सर्चेबिलिटी बढ़ाएँ।
- Automated publishing: निकाली गई PNGs को सीधे वेब‑पेज जेनरेटर या ईमेल टेम्प्लेट्स में फीड करें।
प्रदर्शन संबंधी विचार
- Memory usage: बड़े दस्तावेज़ प्रोसेस करते समय कम से कम
-Xmx2gआवंटित करें; पार्सर डेटा को स्ट्रीम करता है जिससे हीप फुटप्रिंट कम रहता है। - Batch processing: लूप के अंदर प्रत्येक दस्तावेज़ के लिए एक ही
Parserइंस्टेंस को पुन: उपयोग करें ताकि ऑब्जेक्ट निर्माण ओवरहेड कम हो। - File handles: try‑with‑resources ब्लॉक यह सुनिश्चित करता है कि पार्सर तुरंत बंद हो, जिससे डिस्क्रिप्टर लीक नहीं होते।
सामान्य समस्याएँ और समाधान
| समस्या | समाधान |
|---|---|
| OutOfMemoryError बड़े DOCX फ़ाइलों पर | JVM हीप बढ़ाएँ या दस्तावेज़ को छोटे बैचों में प्रोसेस करें। |
| No images returned | सुनिश्चित करें कि दस्तावेज़ में वास्तव में एम्बेडेड इमेजेज़ हैं; कुछ “pictures” VML ड्रॉइंग्स होते हैं जो इमेज के रूप में एक्सपोज़ नहीं होते। |
| Incorrect image orientation | कुछ DOCX इमेजेज़ EXIF रोटेशन स्टोर करती हैं; आवश्यकता होने पर इमेज लाइब्रेरी से पोस्ट‑प्रोसेस करें। |
अक्सर पूछे जाने वाले प्रश्न
Q: GroupDocs.Parser इमेज एक्सट्रैक्शन के लिए कौन से फ़ाइल फ़ॉर्मेट सपोर्ट करता है?
A: यह DOC, DOCX, PDF, PPT, PPTX, और कई अन्य फ़ॉर्मेट को हैंडल करता है, और getImages() मेथड के माध्यम से इमेजेज़ एक्सपोज़ करता है।
Q: क्या मैं पासवर्ड‑प्रोटेक्टेड Word फ़ाइलों से इमेजेज़ निकाल सकता हूँ?
A: हाँ—Parser कंस्ट्रक्टर में पासवर्ड पास करें, और लाइब्रेरी एक्सट्रैक्शन से पहले दस्तावेज़ को डिक्रिप्ट कर देगी।
Q: क्या केवल विशिष्ट इमेज टाइप (जैसे JPEG) निकालने का कोई तरीका है?
A: PageImageArea ऑब्जेक्ट्स प्राप्त करने के बाद, image.getFormat() जांचें और सहेजने से पहले उसी अनुसार फ़िल्टर करें।
Q: क्या लाइब्रेरी असिंक्रोनस प्रोसेसिंग सपोर्ट करती है?
A: जबकि कोर API सिंक्रोनस है, आप एक्सट्रैक्शन लॉजिक को अलग थ्रेड में रैप कर सकते हैं या Java के CompletableFuture का उपयोग करके पैरलल प्रोसेसिंग कर सकते हैं।
Q: प्रोडक्शन उपयोग के लिए क्या मुझे कमर्शियल लाइसेंस चाहिए?
A: मूल्यांकन के लिए फ्री ट्रायल ठीक है, लेकिन कमर्शियल डिप्लॉयमेंट के लिए पेड लाइसेंस आवश्यक है।
अंतिम अपडेट: 2026-08-05
परीक्षण किया गया: GroupDocs.Parser 25.5
लेखक: GroupDocs
संसाधन
- डॉक्यूमेंटेशन: GroupDocs Parser Java Documentation
- API reference: GroupDocs API Reference
- Download: Latest Release
- GitHub: Source code on GitHub
- Free support: GroupDocs Forum
- Temporary license: Obtain a temporary license