This code will not open a PDF that requires a master password, but it's a simple addition to add that to the PDDocument.load().
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
public class pdfRemove {
public static void main(String[] args) throws InvalidPasswordException, IOException {
File file = new File(args[0]);
PDDocument document = PDDocument.load(file);
if (document.isEncrypted()) {
document.setAllSecurityToBeRemoved(true);
}
document.save(new File(args[1]));
document.close();
}
}
No comments:
Post a Comment