iText pdf library
Website search

PDF Protector

No downloads or installation required!

Password protect a PDF using our free online app or learn how it works with our embedded iText 7 Sandbox.


Use the free online PDF Protector app

Click the box below to upload a PDF, or drag and drop a PDF into the box.

You will then be asked to choose an Owner Password to protect the PDF with, and select the Encryption options you want. You can also configure permissions for the PDF, for example if you want to allow printing without entering the password. If you wish, you can also set a User Password to allow restricted access to the PDF.

Click Protect PDF and then download the resulting PDF.

Or play in the iText 7 Sandbox

In this Sandbox you can see how the the protection code works in iText 7, and experiment with changing the code yourself.

Click Upload File and make sure the file name of the PDF you upload matches the name you specify in private static final String ORIG. You can then choose the type of password you want to set by specifying it in private static final byte[] USERPASS or private static final byte[] OWNERPASS. You can set both types of password if you wish.

Then click Execute to run your code. To remove an uploaded file, click the x displayed next to the file name.

You can click the switch at the top of the Sandbox to change between the embedded Java and C# compiler.

import com.itextpdf.kernel.pdf.EncryptionConstants; import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.kernel.pdf.PdfReader; import com.itextpdf.kernel.pdf.PdfWriter; import com.itextpdf.kernel.pdf.WriterProperties; import java.io.FileOutputStream; import java.io.IOException; public class PDFProtection { private static final String ORIG = "/uploads/protect.pdf"; private static final String OUTPUT_FOLDER = "/myfiles/"; private static final byte[] USERPASS = "user".getBytes(); private static final byte[] OWNERPASS = "owner".getBytes(); public static void main(String[] args) throws IOException { PdfReader pdfReader = new PdfReader(ORIG); WriterProperties writerProperties = new WriterProperties(); writerProperties.setStandardEncryption(USERPASS, OWNERPASS, EncryptionConstants.ALLOW_PRINTING, EncryptionConstants.ENCRYPTION_AES_128); PdfWriter pdfWriter = new PdfWriter(new FileOutputStream(OUTPUT_FOLDER + "Protected.pdf"), writerProperties); PdfDocument pdfDocument = new PdfDocument(pdfReader, pdfWriter); pdfDocument.close(); } }
using System.IO; using iText.Kernel.Pdf; namespace PDFProtection { public class PDFProtection { private static string ORIG = "/uploads/protect.pdf"; private static string OUTPUT_FOLDER = "/myfiles/"; private static byte[] USERPASS = System.Text.Encoding.Default.GetBytes("user"); private static byte[] OWNERPASS = System.Text.Encoding.Default.GetBytes("owner"); public static void Main(string[] args) { PdfReader pdfReader = new PdfReader(ORIG); WriterProperties writerProperties = new WriterProperties(); writerProperties.SetStandardEncryption(USERPASS, OWNERPASS, EncryptionConstants.ALLOW_PRINTING, EncryptionConstants.ENCRYPTION_AES_128); PdfWriter pdfWriter = new PdfWriter(new FileStream(OUTPUT_FOLDER + "Protected.pdf", FileMode.Create), writerProperties); PdfDocument pdfDocument = new PdfDocument(pdfReader, pdfWriter); pdfDocument.Close(); } } }
Disclaimer:

iText does not analyze the content of your uploaded or processed files. Users bear sole responsibility for the usage and content of their own files. All uploaded and processed files are deleted from our servers after users leave the page, or automatically after a period of 3 hours.



Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now