-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAadharParser.java
More file actions
57 lines (42 loc) · 1.82 KB
/
Copy pathAadharParser.java
File metadata and controls
57 lines (42 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.ByteArrayInputStream;
import java.io.File;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class AadharParser {
public static void main(String[] args) throws Exception {
// Image Scanner Integration
// Converting .png .jpeg .jpg into a Buffered Image
File aadharFile = new File("Add Your Image Here");
BufferedImage bufferedImage = ImageIO.read(aadharFile);
LuminanceSource src = new BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(src));
String xmlText = "";
try {
Result result = new MultiFormatReader().decode(bitmap);
xmlText = result.getText();
}
catch(NotFoundException e){
System.out.println("QR Not Found");
}
// Parse XML string using an xml Parser
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new ByteArrayInputStream(xmlText.getBytes("UTF-8")));
// Get root element
Element root = doc.getDocumentElement();
System.out.println(root.getAttribute("uid"));
System.out.println(root.getAttribute("name"));
System.out.println(root.getAttribute("yob"));
}
}