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