remove encryption from pdf with pdfbox, like qpdf

后端 未结 1 1162
长发绾君心
长发绾君心 2021-01-05 05:09

With qpdf, you can simply remove restrictions/encryption from a pdf like so:

qpdf --decrypt infile outfile

I would like to do the same thin

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-05 05:16

    This is what you'd need to do. Inspired from the PDFBox WriteDecodedDoc tool. You may have to include the bouncycastle jar (http://www.bouncycastle.org/latest_releases.html)

        if (doc.isEncrypted()) {
            try {
                doc.decrypt("");
                doc.setAllSecurityToBeRemoved(true);
            }
            catch (Exception e) {
                throw new Exception("The document is encrypted, and we can't decrypt it.", e);
            }
        }
    

    0 讨论(0)
提交回复
热议问题