Skip to content

Instantly share code, notes, and snippets.

@OmidNejadabbasi
Created October 12, 2020 08:52
Show Gist options
  • Save OmidNejadabbasi/68fd1d30ed67d252a89250e87cf8929f to your computer and use it in GitHub Desktop.
Save OmidNejadabbasi/68fd1d30ed67d252a89250e87cf8929f to your computer and use it in GitHub Desktop.
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy;
public class Main {
public static void main(String[] args) throws IOException {
PDDocument pdDocument =PDDocument.load(new File("new.pdf"));
AccessPermission access=new AccessPermission();
access.setCanPrint(false);
StandardProtectionPolicy policy=new StandardProtectionPolicy("123", "456", access);
pdDocument.protect(policy);
pdDocument.save("new.pdf");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment