Protect PDF
Published Updated
Type a password twice and save a copy of your PDF that asks for it on opening, encrypted with 256-bit AES whatever the file's PDF version.
One password, and 256-bit AES for every file
Protect PDF encrypts a copy of your file with the password you type, so a reader asks for it before showing any page. Whoever knows the password gets full use of the copy: printing, copying and form filling stay allowed.
The method is the same whatever version number the file's first line carries: AES with a 256-bit key, revision 6. The keys are made with the browser's Web Crypto functions, and every string and stream of the file is encrypted with its own random starting block. The table shows what the copy holds, checked by opening test outputs with qpdf (through pikepdf) and with pdf.js.
What the protected copy holds
| Part of the file | In the protected copy | How it was checked |
|---|---|---|
| Pages, images and fonts | AES-256 encrypted | No test stream decompresses, and page text reads back the same after the password |
| Title, author, XMP, bookmark names, form values | AES-256 encrypted | Test words not found in the raw bytes, shown normally with the password |
| Passwords and permissions | Your password as a salted hash; a random owner password; everything permitted | qpdf reports all permissions on; a wrong password is refused by both readers |
The tool never writes RC4, which the qpdf manual's chapter on PDF encryption calls obsolete and insecure. Only the file ID and the encryption dictionary stay readable, which is how the standard wants it.
The encryption dictionary, read back from the file
Protect PDF was run in Google Chrome 156, Chromium 153 (Playwright build, not Google Chrome), Firefox 155 and Playwright's WebKit build (not the Safari app) with four accepted passwords on a test PDF and once on a 200-page file. Each of the 20 protected copies was opened with qpdf (through pikepdf 9.11.0) and pdf.js 5.4.624. All 20 carried the same /Encrypt entries:
| Entry | Value in the file | What qpdf reports |
|---|---|---|
| /Filter, /V, /R | /Standard, 5, 6 | Revision 6 of the standard password handler |
| /Length; /CF /StdCF | 256; /CFM /AESV3, /AuthEvent /DocOpen, /Length 32 | 256-bit key; AES-256 for streams, strings and attached files |
| /StmF, /StrF | /StdCF, /StdCF | Streams and strings both use that AES-256 filter |
| /P | -4 | All eight permission flags allowed, from printing and copying to form filling and page assembly |
| /EncryptMetadata | true | The XMP metadata is encrypted with the rest |
| /O, /U, /OE, /UE, /Perms | Present | Password checks, the wrapped file key and the encrypted copy of the permissions |
The file header says PDF 1.7, and pikepdf reports Adobe extension level 8 declared in it. A wrong password and an empty one were refused by both readers, with one exception covered in the questions below: past 127 bytes, extra characters do not count.
| Checked in the 4-page test PDF | Result |
|---|---|
| 22 marker strings in the page text, title, author, XMP, a bookmark, a form value, a comment, a link address and an attached file | None found in the raw bytes of any of the 16 protected copies |
| The same parts after opening with the password | All there: title and author, XMP, the bookmark, the filled form field, the comment and link, the attached file and the page text |
| File size | 4,206 bytes became 9,438 in all four browsers; the 200-page, 464,937-byte file became 736,380 bytes |
| Time from Protect PDF to the download link | 21 to 83 ms for the small file, 110 ms (Chrome 156) to 153 ms (Firefox 155) for 200 pages |
Passwords the box accepts and refuses
The same messages appeared in all four browsers:
| Typed in both boxes | Result |
|---|---|
| Nothing | Please enter a password. |
| abc, then abd in the second box | Passwords do not match. |
| café | The message about letters with accents or marks |
| A padlock emoji followed by lock | The message about emoji, full-width letters, ligatures and special spaces |
| €uro | The message about ß, ø, € and curly quotes |
| 128 English letters, or 64 Cyrillic letters (128 bytes) | This password is too long. PDF passwords can be up to 127 bytes |
| 16 English characters with spaces, 6 Cyrillic letters and 4 digits (16 bytes), 4 Chinese characters (12 bytes), 127 English letters | Accepted; each copy opened with its password in qpdf and pdf.js |
| Any password for a PDF that is already encrypted | This PDF is already protected, before any password is asked for |
Adding a password
Step 1
Add the PDF
Its page count and size appear once it is read. An already encrypted PDF is turned away.
Step 2
Type the password twice
Both boxes must match exactly, capitals included. Up to 127 bytes; letters with accents or marks, such as é, ą or ї, are turned away with a message.
Step 3
Protect and download
Click Protect PDF and save the copy that ends in -protected.pdf. Open it once with the password before deleting the original.
Readers and the 256-bit format
Revision 6 belongs to PDF 2.0 and to an Adobe extension of PDF 1.7, so the copy declares that extension. In tests it opened in pdf.js, the engine behind the PDF viewer of Firefox, and in qpdf. A very old reader written before 256-bit AES existed may not open it at all, even with the right password.
Strings are covered one by one, as the PDF standard (ISO 32000-1, section 7.6.1) asks when it says encryption applies to all strings and streams. A Mac or Chrome PDF therefore gets the same protection as any other, with nothing to prepare first.
Limits of the password box
- Characters: plain letters of any script, digits and symbols. Letters with accents or marks (é, ą, ό, ї), Korean syllables, kana with ゛ or ゜, symbols such as € or curly quotes, emoji, ligatures, full-width letters, invisible or control characters get a message instead. With Hebrew or Arabic letters, the password must start and end with one of them and hold no Latin letters, a SASLprep rule (RFC 4013) that the standard adopts.
- Length: up to 127 bytes, which is 127 English characters or about 63 Hebrew, Arabic or Cyrillic ones. Every character counts, and a longer password is refused with a message rather than cut short.
- Already encrypted files are refused, even ones that only limit printing. Clear them with Unlock PDF first.
Password protection questions
Which encryption does the protected PDF use?
AES with a 256-bit key, revision 6 of the standard security handler, the strongest method the PDF standard defines. Your file's version makes no difference: test files of versions 1.3, 1.4, 1.5, 1.7 and 2.0 all came out with it, as reported by both qpdf and pdf.js.
Can someone open the file without the password?
Not without guessing the password. The file key is random and can be recovered only from your password, through many rounds of SHA-2 hashing, so a long password used nowhere else is what keeps the file closed.
Will people still be able to print or copy text?
Yes. Every permission is left on, so whoever opens the copy with the password can print, copy text and fill in forms. A separate owner password is generated at random and never shown; since nothing is restricted, nobody needs it.
Are the title and bookmark names hidden as well?
Yes. The title, author, keywords, XMP metadata, bookmark names, comments and form values are encrypted along with the pages, so a text editor shows only scrambled bytes. After the password is entered, a reader shows them as before.
What happens if I forget the password?
The file stays closed. The password never leaves your browser and is not kept anywhere, so there is no reset. Keep the original until the copy has opened.
Can the password use Cyrillic, Hebrew or Chinese letters?
Yes, as long as no letter carries an accent or mark. In tests, Hebrew, Arabic, Chinese and Russian passwords opened the file in pdf.js, qpdf and Apple's PDFKit. PDFKit, the engine of Apple Preview, failed on letters such as é, ą, ό or ї, on Korean syllables and on kana with ゛ or ゜, so the tool refuses those, along with emoji, full-width letters and special spaces.
Does a longer password that starts the same way also open the file?
Only past the 127-byte limit. Readers use the first 127 bytes of what is typed, so with a 127-letter password, the same letters plus one more opened the copy in both qpdf and pdf.js. With a 16-character password, adding one character was refused, as was an empty password.
Do attachments, bookmarks and form fields survive protection?
Yes. After the password, the test copy still had its attached file, its bookmark, its filled form field, its comment and link, its title and its XMP metadata. Before the password, none of their text could be found in the file's bytes.
How much bigger does the protected file get?
Some, because each string and stream gets its own 16-byte starting block and padding, and the file is written without compressed object streams. A 200-page text PDF grew from 464,937 to 736,380 bytes, and a small 4-page test file from 4,206 to 9,438 bytes.
Related guide
How to compress, merge and convert PDFs without uploading them. The guide compares AES-256 with the older RC4 method and notes what a password does and does not cover.