遮盖 UIDAI Aadhaar PDF 中的 Aadhaar 号码

huangapple go评论78阅读模式
英文:

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 &lt; refs.getArrayList().size(); i++) {
        PRStream stream = (PRStream) refs.getDirectObject(i);
        byte[] data = PdfReader.getStreamBytes(stream);
        stream.setData(new String(data).replace(&quot;8989 7890 4567&quot;, &quot;XXXX XXXX 4567&quot;).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.

https://github.com/rinkeshjain/aadhaar-mask

huangapple
  • 本文由 发表于 2020年9月6日 03:20:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63757726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定