<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.24</version>
</dependency>
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
import java.io.File;
import java.io.IOException;
public class RemovePdfRestrictions {
public static void main(String[] args) {
File inputFile = new File("input.pdf"); // 输入文件路径
File outputFile = new File("output.pdf"); // 输出文件路径
try (PDDocument document = PDDocument.load(inputFile)) {
// 放开所有权限
document.setAllSecurityToBeRemoved(true);
// 创建一个允许所有操作的访问权限对象
AccessPermission newAccessPermission = new AccessPermission();
// 应用新的访问权限设置
document.setAccessPermission(newAccessPermission);
// 保存修改后的文档
document.save(outputFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}