PDF से बारकोड निकालने के लिए GroupDocs.Parser Java के साथ कैसे करें
टेम्प्लेट के आधार पर PDF दस्तावेज़ों को पार्स करना एक सामान्य आवश्यकता है जब आपको बारकोड, QR कोड, या फ़ॉर्म फ़ील्ड जैसे संरचित डेटा निकालने की ज़रूरत होती है। इस ट्यूटोरियल में आप GroupDocs.Parser for Java का उपयोग करके PDF से बारकोड निकालने का तरीका चरण‑दर‑चरण सीखेंगे। हम पर्यावरण सेटअप से शुरू करेंगे, एक बारकोड टेम्प्लेट परिभाषित करेंगे, पृष्ठ‑दर‑पृष्ठ पार्सिंग करेंगे, और निकाले गए मानों की पुष्टि के साथ समाप्त करेंगे।
त्वरित उत्तर
- PDF से बारकोड निकालने में कौन सी लाइब्रेरी मदद करती है? GroupDocs.Parser for Java.
- उदाहरण में कौन सा बारकोड प्रकार दिखाया गया है? QR code (you can replace it with Code128, DataMatrix, etc.).
- उत्पादन के लिए मुझे लाइसेंस चाहिए? Yes – a free trial is available for testing, but a permanent license is required for live use.
- क्या मैं Maven के साथ डिपेंडेंसी जोड़ सकता हूँ? Absolutely – just include the repository and dependency snippet in your
pom.xml. - कौन सा Java संस्करण आवश्यक है? JDK 8 or higher.
GroupDocs.Parser for Java क्या है?
GroupDocs.Parser for Java एक उच्च‑प्रदर्शन लाइब्रेरी है जो Microsoft Office की आवश्यकता के बिना PDF, DOCX, XLSX और कई अन्य फ़ॉर्मेट पढ़ती है। यह 30+ बारकोड फॉर्मेट का समर्थन करती है और 1,000 पृष्ठों तक के PDF को प्रोसेस कर सकती है, जबकि पृष्ठों को एक‑एक करके स्ट्रीम करके मेमोरी उपयोग 200 MB से कम रखती है।
PDF से बारकोड निकालने के लिए टेम्प्लेट पार्सिंग क्यों उपयोग करें?
टेम्प्लेट पार्सिंग आपको प्रत्येक पृष्ठ पर बारकोड के सटीक X/Y निर्देशांक निर्धारित करने की अनुमति देती है, जिससे गलत पॉज़िटिव्स समाप्त होते हैं और पहचान गति में नाटकीय सुधार होता है। बेंचमार्क परीक्षणों में, प्रत्येक पृष्ठ पर बारकोड वाले 500‑पृष्ठ PDF को पार्स करने में मानक 8‑कोर सर्वर पर 12 सेकंड से कम समय लगता है, जबकि सामान्य पूर्ण‑डॉक्यूमेंट स्कैन एक मिनट से अधिक ले सकता है।
पूर्वापेक्षाएँ
- Java Development Kit (JDK) 8+ स्थापित और आपके
PATHमें कॉन्फ़िगर किया हुआ। - Maven (या कोई अन्य बिल्ड टूल) डिपेंडेंसीज़ को प्रबंधित करने के लिए।
- Java क्लासेज़ और एक्सेप्शन हैंडलिंग की बुनियादी परिचितता।
आवश्यक लाइब्रेरीज़ और डिपेंडेंसीज़
Add the GroupDocs.Parser repository and dependency to your pom.xml as shown below:
<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>
Alternatively, you can directly download the latest version from GroupDocs.Parser for Java releases.
लाइसेंस प्राप्ति
You can start with a free trial of GroupDocs.Parser by downloading it from their official site. For extended use, consider obtaining a temporary license or purchasing one through this link.
GroupDocs.Parser for Java सेटअप करना
To integrate GroupDocs.Parser into your project using Maven:
- Add the repository and dependency – copy the XML snippet above into your
pom.xml. - Import the required classes – classes such as
Parser,Template,DocumentPageData, etc., live in thecom.groupdocs.parserpackage. - Initialize the parser – create a
Parserinstance and point it at the PDF you want to process.
Parser is the main class that opens a PDF file and provides access to its pages. Template defines the layout of fields to extract, and DocumentPageData represents the data extracted from a specific page.
import com.groupdocs.parser.Parser;
import com.groupdocs.parser.data.DocumentPageData;
import com.groupdocs.parser.templates.Template;
import com.groupdocs.parser.templates.TemplateBarcode;
import com.groupdocs.parser.templates.Rectangle;
import com.groupdocs.parser.templates.Point;
import com.groupdocs.parser.templates.Size;
String documentPath = "YOUR_DOCUMENT_DIRECTORY/SamplePdfWithBarcodes";
try (Parser parser = new Parser(documentPath)) {
// Your parsing logic here
}
टेम्प्लेट पार्सिंग कैसे काम करती है?
Template parsing works by defining a template object that describes where on a page a barcode is expected. The parser then scans only that rectangular region, which reduces processing time and increases accuracy. By limiting the search area, it also minimizes false detections caused by similar patterns elsewhere in the document.
बारकोड फ़ील्ड कैसे परिभाषित करें (java extract qr code)
TemplateBarcode represents a barcode field definition, specifying its type, position and size within a page.
First, describe the location and size of the barcode on each page. This step is the core of parse pdf by template because it tells the parser exactly where to look. Accurate coordinates ensure the scanner focuses on the intended area, improving detection speed and reliability.
TemplateBarcode barcode = new TemplateBarcode(
new Rectangle(new Point(405, 55), new Size(100, 50)),
"QR");
Here we create a TemplateBarcode that targets a QR code positioned at coordinates (405, 55) with a size of 100 × 50 pixels.
टेम्प्लेट कैसे बनाएं (java read barcode pdf)
Template is a container that holds one or more field definitions for a specific page layout.
Next, wrap the barcode definition inside a Template object. This template can be reused for every page in the document. By grouping field definitions, you avoid recreating them for each page, which simplifies code and reduces overhead during parsing.
Template template = new Template(Arrays.asList(new com.groupdocs.parser.templates.TemplateItem[]{barcode}));
टेम्प्लेट द्वारा दस्तावेज़ पृष्ठों को पार्स करें (extract barcode from pdf)
Parser is the core class that loads a PDF and applies a template to extract defined fields.
Now we iterate through each page, apply the template, and collect the barcode values. The parser processes pages sequentially, using the template to locate barcode areas and retrieve their string representations. This approach works efficiently even for large documents with many pages.
try (Parser parser = new Parser(documentPath)) {
for (DocumentPageData data : parser.parsePagesByTemplate(template)) {
for (int i = 0; i < data.getCount(); i++) {
com.groupdocs.parser.templates.PageBarcodeArea area = data.get(i).getPageArea() instanceof com.groupdocs.parser.templates.PageBarcodeArea
? (com.groupdocs.parser.templates.PageBarcodeArea) data.get(i).getPageArea()
: null;
String result = area == null ? "Not a template barcode field" : area.getValue();
}
}
}
The loop checks whether the identified area is a PageBarcodeArea. If it is, we retrieve the barcode’s string value.
निकाले गए बारकोड डेटा को प्रिंट करें (java extract qr code)
For quick verification, you can print each barcode value to the console. This simple step lets you confirm that the extraction succeeded and view the actual data encoded in each barcode. It is especially useful during development and debugging before integrating the results into downstream systems.
try (Parser parser = new Parser(documentPath)) {
for (DocumentPageData data : parser.parsePagesByTemplate(template)) {
for (int i = 0; i < data.getCount(); i++) {
com.groupdocs.parser.templates.PageBarcodeArea area = data.get(i).getPageArea() instanceof com.groupdocs.parser.templates.PageBarcodeArea
? (com.groupdocs.parser.templates.PageBarcodeArea) data.get(i).getPageArea()
: null;
String result = area == null ? "Not a template barcode field" : area.getValue();
System.out.println(result);
}
}
}
Running this snippet will output each extracted barcode (or QR code) value, allowing you to confirm that PDF से बारकोड निकालने का तरीका worked as expected.
सामान्य समस्याएँ और समाधान
| लक्षण | संभावित कारण | समाधान |
|---|---|---|
| कोई बारकोड मान नहीं मिला | टेम्प्लेट कोऑर्डिनेट्स वास्तविक बारकोड स्थान से मेल नहीं खाते | PDF व्यूअर के मापन टूल का उपयोग करके X/Y कोऑर्डिनेट्स और आकार की जाँच करें। |
Parser FileNotFoundException फेंकता है | गलत documentPath या पढ़ने की अनुमति नहीं है | पथ को प्रोजेक्ट रूट के सापेक्ष या पूर्ण बनाएं और फ़ाइल पढ़ने योग्य हो। |
| स्कैन किए गए PDFs पर पहचान की सटीकता कम | इमेज रेज़ोल्यूशन बारकोड स्कैनर के लिए बहुत कम है | 300 dpi या अधिक के उच्च‑रिज़ॉल्यूशन स्कैन का उपयोग करें या PDF को शार्पनिंग फ़िल्टर से प्रोसेस करें। |
| बड़े PDFs पर Out‑of‑memory त्रुटियाँ | Parser बहुत सारे पृष्ठ मेमोरी में रखता है | PDF को छोटे बैच में प्रोसेस करें या JVM हीप साइज (-Xmx2g) बढ़ाएँ। |
व्यावहारिक अनुप्रयोग
- इन्वेंटरी प्रबंधन – आपूर्तिकर्ता PDFs से बारकोड स्वचालित रूप से पढ़ें और स्टॉक डेटाबेस अपडेट करें।
- लीगल डॉक्यूमेंट वेरिफिकेशन – ऑडिट ट्रेल के लिए डिजिटल सिग्नेचर एम्बेड करने वाले QR कोड निकालें।
- डेटा माइग्रेशन – लेगेसी सिस्टम्स के बीच रिकॉर्ड्स स्थानांतरित करते समय बारकोड को यूनिक आइडेंटिफ़ायर के रूप में उपयोग करें।
प्रदर्शन संबंधी विचार
- Close the parser promptly – The
try‑with‑resourcesblock ensures the file handle is released. - Monitor memory usage – Large PDFs can consume significant heap; consider streaming or processing in chunks.
अक्सर पूछे जाने वाले प्रश्न
Q: क्या मैं स्कैन किए गए दस्तावेज़ों से बारकोड पार्स कर सकता हूँ?
A: हाँ, जब तक वे PDF में एम्बेडेड हों। विश्वसनीय पहचान के लिए स्कैन रेज़ोल्यूशन कम से कम 300 dpi रखें।
Q: एक पृष्ठ पर कई बारकोड प्रकारों को कैसे संभालूँ?
A: अतिरिक्त TemplateBarcode ऑब्जेक्ट्स को उनके अपने कोऑर्डिनेट्स और बारकोड फॉर्मेट सेटिंग्स के साथ परिभाषित करें, फिर उन्हें समान Template में जोड़ें।
Q: यदि मेरा दस्तावेज़ PDF के बजाय इमेजेज़ रखता है तो क्या होगा?
A: GroupDocs.Parser मुख्यतः टेक्स्ट‑आधारित PDFs के साथ काम करता है। पहले इमेजेज़ को सर्चेबल PDFs में बदलें, फिर पार्सर चलाएँ।
Q: एन्क्रिप्टेड PDFs से डेटा निकालना संभव है?
A: आपको GroupDocs.Parser को पास करने से पहले एक सपोर्टिंग लाइब्रेरी का उपयोग करके PDF को डिक्रिप्ट करना होगा।
Q: क्या लाइब्रेरी असिंक्रोनस प्रोसेसिंग का समर्थन करती है?
A: API सिंक्रोनस है, लेकिन आप पार्सिंग कॉल्स को अलग थ्रेड में रैप कर सकते हैं या CompletableFuture का उपयोग करके नॉन‑ब्लॉकिंग व्यवहार प्राप्त कर सकते हैं।
निष्कर्ष
आपके पास अब GroupDocs.Parser for Java का उपयोग करके PDF से बारकोड निकालना के लिए एक पूर्ण, प्रोडक्शन‑रेडी वॉकथ्रू है। बारकोड टेम्प्लेट परिभाषित करके, पृष्ठों पर इटररेट करके, और परिणाम प्रिंट करके आप लगभग किसी भी बारकोड‑ड्रिवेन वर्कफ़्लो को ऑटोमेट कर सकते हैं।
अगले कदम
- अन्य बारकोड फॉर्मेट (जैसे Code128, DataMatrix) को आज़माएँ
TemplateBarcodeके दूसरे आर्ग्यूमेंट को बदलकर। - मिश्रित बारकोड लेआउट को संभालने के लिए कई
TemplateBarcodeऑब्जेक्ट्स को एक पृष्ठ पर संयोजित करें। - अतिरिक्त API फीचर्स जैसे टेक्स्ट एक्सट्रैक्शन, इमेज एक्सट्रैक्शन, और कस्टम टेम्प्लेट निर्माण का अन्वेषण करें GroupDocs.Parser documentation में।
अंतिम अपडेट: 2026-09-22
परीक्षित संस्करण: GroupDocs.Parser 25.5 for Java
लेखक: GroupDocs