英文:
Masking aadhaar number in an UIDAI aadhaar pdf
问题
public static void main(String[] args) throws IOException, DocumentException {
File file = new File(DEST);
file.getParentFile().mkdirs();
new MainClassName().manipulatePdf(SRC, DEST);
}
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfDictionary dict = reader.getPageN(1);
PdfObject object = dict.getDirectObject(PdfName.CONTENTS);
PdfArray refs = null;
if (dict.get(PdfName.CONTENTS).isArray()) {
refs = dict.getAsArray(PdfName.CONTENTS);
} else if (dict.get(PdfName.CONTENTS).isIndirect()) {
refs = new PdfArray(dict.get(PdfName.CONTENTS));
}
for (int i = 0; i < refs.getArrayList().size(); i++) {
PRStream stream = (PRStream) refs.getDirectObject(i);
byte[] data = PdfReader.getStreamBytes(stream);
stream.setData(new String(data).replace("8989 7890 4567", "XXXX XXXX 4567").getBytes());
}
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
stamper.close();
reader.close();
}
英文:
Does anybody know how to mask aadhaar number in an aadhaar pdf downloaded from UIDAI website.
I have already tried below code for itext. It is not working for an aadhaar PDF but is working for other normal pdfs
public static void main(String[] args) throws IOException, DocumentException {
File file = new File(DEST);
file.getParentFile().mkdirs();
new MainClassName().manipulatePdf(SRC, DEST);
}
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfDictionary dict = reader.getPageN(1);
PdfObject object = dict.getDirectObject(PdfName.CONTENTS);
PdfArray refs = null;
if (dict.get(PdfName.CONTENTS).isArray()) {
refs = dict.getAsArray(PdfName.CONTENTS);
} else if (dict.get(PdfName.CONTENTS).isIndirect()) {
refs = new PdfArray(dict.get(PdfName.CONTENTS));
}
for (int i = 0; i < refs.getArrayList().size(); i++) {
PRStream stream = (PRStream) refs.getDirectObject(i);
byte[] data = PdfReader.getStreamBytes(stream);
stream.setData(new String(data).replace("8989 7890 4567", "XXXX XXXX 4567").getBytes());
}
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
stamper.close();
reader.close();
}
Tried suggestions from this post too (i.e, using pdfbox)
https://stackoverflow.com/questions/52027733/search-and-replace-text-in-pdf-using-java
Even that is not working for an aadhaar PDF but is working for a normal pdf
(I know we can download a masked aadhaar pdf from UIDAI website itself, but I need to do it through JAVA)
答案1
得分: 1
你可以将你的PDF转换成图片,然后借助谷歌云OCR进行处理,然后对文本进行遮盖,最后将其转换回PDF格式。
以下是一个使用JavaScript的示例项目。
https://github.com/rinkeshjain/aadhaar-mask
英文:
you can convert your PDF to an Image then with help of Google Cloud OCR
and then mask text and convert it back to PDF.
Here is Sample Project in javascript.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论