How to disallow content copying and printing of a PDF (aka securing a PDF)

Submitted by Jochus on Mon, 11/02/2013 - 21:18 | Posted in: Java

I came across some issues with processing secured PDF's. These PDF files were encrypted. After reading the following documentation:…, I tried securing one of my own PDF's.


Encrypting the PDF so text cannot be copy/pasted and the PDF could not be printed


  • iText
  • BouncyCastle jars

Libraries used

  • iText: 5.3.5
  • BouncyCastle: bcprov-jdk14-1.47.jar and bcprov-ext-jdk14-1.47.jar


import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
public class EncryptPDF {
	private static final String INPUT_FILENAME = "/tmp/test.pdf";
	private static final String OUTPUT_FILENAME = "/tmp/test_encrypted.pdf";
	private static final String USER_PASSWORD = "";
	private static final String OWNER_PASSWORD = "foobar";
	public static void main(String[] args) {
		PdfReader reader = null;
		FileOutputStream out = null;
		PdfStamper stamper = null;
		try {
			// Define input
			reader = new PdfReader(INPUT_FILENAME);
			// Define output
			out = new FileOutputStream(OUTPUT_FILENAME);
			// Encrypt document
			stamper = new PdfStamper(reader, out);
			stamper.setEncryption(USER_PASSWORD.getBytes(), OWNER_PASSWORD.getBytes(), 0, PdfWriter.STANDARD_ENCRYPTION_128);
		} catch (Exception ex) {
		} finally {
			if (stamper != null) {
				try {
				} catch (Exception ex) {
			if (reader != null) {
				try {
				} catch (Exception ex) {
			if (out != null) {
				try {
				} catch (Exception ex) {


You can also play with the permissions by providing PdfWriter perms instead of the value "0".

stamper.setEncryption(USER_PASSWORD.getBytes(), OWNER_PASSWORD.getBytes(), PdfWriter.ALLOW_ASSEMBLY | PdfWriter.ALLOW_COPY, PdfWriter.STANDARD_ENCRYPTION_128);

Check if PDF is secured

  • When opening the PDF with Acrobat Reader, the title should end with: (SECURED)
  • Open the properties of the PDF in Acrobat Reader ( + D on a Mac ) and look at Document Restrictions Summary

Add new comment

The content of this field is kept private and will not be shown publicly.


  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.