how to get pdf origin contents using itext

New Here ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

I will make the problem concrete. I currently have three PDFs

The first PDF is a pure PDF without any signature. The link is as follows, https://drive.google.com/file/d/14gPZaL2AClRlPb5R2FQob4BBw31vvqYk/view?  usp=sharingskytv The second PDF, I digitally signed the first PDF using adobe_acrobat_dc, the link is here, https://drive.google.com/file/d/1CSrWV7SKrWUAJAf2uhwRZ8ephGa_uYYs/view?usp=sharing,

The third PDF is generated like this, I used the code you once provided as below

        com.itextpdf.kernel.pdf.PdfReader pdfReader = new com.itextpdf.kernel.pdf.PdfReader(new 
        FileInputStream("C:\\Users\\Dell\\Desktop\\test2.pdf"));
        com.itextpdf.kernel.pdf.PdfDocument pdfDocument = new com.itextpdf.kernel.pdf.PdfDocument(pdfReader);
        SignatureUtil signatureUtil = new SignatureUtil((pdfDocument));
        for(String name: signatureUtil.getSignatureNames()){
            System.out.println(name);
            PdfSignature signature = signatureUtil.getSignature(name);
            PdfArray b = signature.getByteRange();
            long[] longs = b.asLongArray();
            RandomAccessFileOrArray rf = pdfReader.getSafeFile();
            try (InputStream rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(rf.createSourceView(),longs));
                 ByteArrayOutputStream byteArrayOutputStream = new com.itextpdf.io.source.ByteArrayOutputStream();) {
                byte[] buf = new byte[8192];
                int rd;
                while ((rd = rg.read(buf, 0, buf.length)) > 0) {
                    byteArrayOutputStream.write(buf, 0, rd);
                }
                byte[] bytes1 = byteArrayOutputStream.toByteArray();

                
                String s2 = DatatypeConverter.printBase64Binary(bytes1);
                
                }
}
                

Process the second PDF to get the base64 encoded form of the third PDF, finally,the third pdf link is https://drive.google.com/file/d/1LSbZpaVT9GrfotXplmKWl6HaCvxmaoH9/view?usp=sharing

My question is, is there a method which the input parameter is the first PDF and the output is the third PDF

 

[Mod note: moved to Acrobat forum]

TOPICS
How to

Views

32

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

LATEST

This has nothing to do with Acrobat. You should ask in a forum about iText.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines