PDF With Limited Permissions In Java Using iText

Chapter: iText Last Updated: 12-08-2016 08:34:51 UTC

Program:

            /* ............... START ............... */
                
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.codec.Base64.OutputStream;

public class JavaiTextPDFFilePermission {
	
	public static void main(String[] args) {
		
		try {
	        FileOutputStream file = new FileOutputStream(new File(
	                "LimitedAccess.pdf"));
	        Document document = new Document();
	        PdfWriter writer = PdfWriter.getInstance(document, file);
	 
	        writer.setEncryption("".getBytes(), "".getBytes(),
	                PdfWriter.ALLOW_PRINTING , //Only printing allowed; Try to copy text !!
	                PdfWriter.ENCRYPTION_AES_128);
	 
	        document.open();
	        document.add(new Paragraph("Limited Access File !!"));
	        document.close();
	        file.close();
	 
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
		
	}
}
                /* ............... END ............... */
        

Notes:

  • Following are several permission values:
  • PdfWriter.ALLOW_PRINTING
  • PdfWriter.ALLOW_ASSEMBLY
  • PdfWriter.ALLOW_COPY
  • PdfWriter.ALLOW_DEGRADED_PRINTING
  • PdfWriter.ALLOW_FILL_IN
  • PdfWriter.ALLOW_MODIFY_ANNOTATIONS
  • PdfWriter.ALLOW_MODIFY_CONTENTS
  • PdfWriter.ALLOW_SCREENREADERS

Tags

PDF With Limited Permissions, iText, Java

Similar Programs Chapter Last Updated
Java Set Background To Table Example iText 22-07-2017
Java PDF Hello World Example iText 14-08-2016
Java PDF Formatting Using iText iText 14-08-2016
Read Existing PDF In Java iText 14-08-2016
Read OR Modify PDF File In Java Using iText iText 12-08-2016
Password Protected PDF Files Using Java iText iText 12-08-2016
Styling Or Formatting PDF In Java Using iText iText 11-08-2016
Create Lists In PDF Using Java iText iText 10-08-2016
Create Tables In PDF Using Java iText iText 10-08-2016
Add Images To PDF In Java Using iText iText 10-08-2016
File Attributes To PDF In Java Using iText iText 10-08-2016
PDF Creation In Java Using iText iText 10-08-2016

1