9

QPDFを使用すると、次のように PDF ファイルから制限/暗号化を簡単に削除できます。

qpdf --decrypt infile outfile

JavaのPDFBoxで同じことをしたいと思います:

PDDocument doc = PDDocument.load(inputFilename);
if (doc.isEncrypted()) {
   // remove the encryption to alter the document
}

でこれを試しましたStandardDecryptionMaterialが、所有者のパスワードがわかりません。QPDFはこれをどのように行いますか?

サンプル ドキュメント:
https://issues.apache.org/jira/secure/attachment/12514714/in.pdf

4

1 に答える 1

21

これはあなたがする必要があることです(PDFBox WriteDecodedDocコマンドラインツールに触発されました):

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);
    }
}

注: Bouncy Castle JARを含める必要がある場合があります。

于 2013-02-05T05:03:57.930 に答える