Get started

How to prevent PDF editing (permissions, flattening, and watermarks)

Restrict editing, copying, and printing in any PDF using permissions passwords, flattening, and watermarks. Free tools and code examples included.

benoitded11 min read

A signed contract, a completed tax form, a published report: once a PDF leaves your hands, you often want to prevent the recipient from changing it. The PDF specification offers three mechanisms for this, each with different trade-offs.

This guide covers all three and is honest about their limits.

What does "prevent PDF editing" actually mean?

PDF editing prevention is not a single feature. It is a combination of three independent mechanisms defined in the PDF specification (ISO 32000-2:2020):

MechanismWhat it doesWhat it does not do
Permissions passwordTells the viewer to block edit, copy, printDoes not encrypt content or stop tools that ignore permissions
FlatteningConverts form fields and annotations to static pixelsDoes not protect body text from PDF editors
WatermarkAdds a visible overlay marking ownershipDoes not block any action, only deters misuse

No single mechanism is absolute. Combining all three gives you the strongest practical protection available in the PDF format.

How PDF permissions work

The PDF specification defines a 32-bit permissions flag stored in the file's encryption dictionary. Each bit controls a specific operation. The Adobe Acrobat security documentation describes the main flags:

  • Bit 3: print the document
  • Bit 4: modify the document
  • Bit 5: extract text and graphics
  • Bit 6: add or modify annotations and form fields
  • Bit 12: print at high resolution

An owner password (also called permissions password) sets these flags. Anyone can open the file without entering a password, but the viewer checks the flags before allowing restricted operations. Adobe Acrobat, Chrome's built-in PDF viewer, and macOS Preview all respect these flags.

The honesty caveat

PDF permissions are a policy, not a lock. The flag bits are metadata, not cryptography. Any tool that reads the raw PDF byte stream can ignore the flags entirely. Open-source libraries like pdf-lib, PyMuPDF, and qpdf can open a permissions-restricted PDF and modify it without the owner password.

This is by design. The PDF spec delegates enforcement to the viewer application. If you need true tamper-proofing, digital signatures (PKI-based, not covered here) are the correct mechanism.

For most business use cases (contracts sent to clients, published reports, completed forms), permissions are sufficient because recipients use standard viewers.

Method 1: PDF4.dev Protect PDF tool (free, browser-based)

The fastest way to set permissions on a PDF. No account, no upload, no installation.

  1. Go to Protect PDF
  2. Drop your file onto the upload area
  3. Enter a permissions password (12+ characters recommended)
  4. Click Protect PDF and download the result

The file never leaves your browser. The tool uses the @pdfsmaller/pdf-encrypt-lite library with RC4-128 encryption, which is sufficient for setting permissions flags on everyday documents.

Protect PdfTry it free

Method 2: qpdf (command line, AES-256)

qpdf is a free, open-source tool that produces AES-256 encrypted output with granular permission control.

# Block editing, copying, and printing (file opens without password)
qpdf --encrypt "" owner-password-here 256 \
  --print=none \
  --modify=none \
  --extract=n \
  -- input.pdf restricted.pdf

The empty string "" means no open password: anyone can view the file. The 256 argument uses AES-256 encryption for the permissions dictionary, the strongest option available per the qpdf encryption reference.

Granular permission flags in qpdf

# Allow printing but block editing and copying
qpdf --encrypt "" owner-password 256 \
  --print=full \
  --modify=none \
  --extract=n \
  -- input.pdf restricted.pdf
 
# Allow form filling only (no other modifications)
qpdf --encrypt "" owner-password 256 \
  --print=full \
  --modify=form \
  --extract=n \
  -- input.pdf restricted.pdf
FlagValuesEffect
--printfull, low, noneControls printing. low allows only low-resolution output.
--modifyall, annotate, form, assembly, noneControls modification level. form allows only form filling.
--extracty, nControls text and image extraction (copy/paste).

Install qpdf on macOS with brew install qpdf or on Ubuntu with sudo apt install qpdf.

Method 3: PyMuPDF (Python)

PyMuPDF can set PDF permissions programmatically. The permissions parameter accepts a bitmask matching the PDF specification flags.

import pymupdf
 
doc = pymupdf.open("input.pdf")
 
# Permission flags (pymupdf constants)
# PDF_PERM_PRINT = 4
# PDF_PERM_MODIFY = 8
# PDF_PERM_COPY = 16
# PDF_PERM_ANNOTATE = 32
 
# Set owner password, allow printing only
perm = pymupdf.PDF_PERM_PRINT  # bit 3 only
doc.save(
    "restricted.pdf",
    encryption=pymupdf.PDF_ENCRYPT_AES_256,
    owner_pw="owner-secret",
    user_pw="",              # no open password
    permissions=perm,
)

Setting user_pw="" means the file opens freely. Only the specified permissions are allowed.

Method 4: Ghostscript

Ghostscript can rewrite a PDF with permission restrictions using its pdfwrite device.

gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \
   -sOwnerPassword=owner-secret \
   -sUserPassword="" \
   -dPermissions=-3904 \
   -sOutputFile=restricted.pdf input.pdf

The -dPermissions value is a signed 32-bit integer representing the PDF permission flags. -3904 disables modify, copy, and annotate while allowing print. Calculating the correct bitmask requires reading the PDF spec directly, so qpdf's named flags are easier to use for most cases.

Method 5: pdf-lib (Node.js / TypeScript)

pdf-lib does not natively support setting PDF encryption or permissions. To restrict a PDF in Node.js, pass the output through qpdf as a child process.

import { execSync } from "child_process";
import { writeFileSync, readFileSync, unlinkSync } from "fs";
 
// Assume pdfBytes is a Uint8Array from pdf-lib
writeFileSync("/tmp/input.pdf", pdfBytes);
 
execSync(
  `qpdf --encrypt "" "owner-secret" 256 ` +
  `--print=full --modify=none --extract=n ` +
  `-- /tmp/input.pdf /tmp/restricted.pdf`
);
 
const restricted = readFileSync("/tmp/restricted.pdf");
unlinkSync("/tmp/input.pdf");
unlinkSync("/tmp/restricted.pdf");

This approach works in any server-side environment where qpdf is installed.

Flattening as a complementary strategy

Flattening converts interactive PDF elements into static page content. Form field values, annotations, comments, and signature widgets are rendered into the page as drawn shapes and text, then the original interactive objects are removed.

After flattening:

  • A filled text field becomes regular text drawn on the page
  • A checkbox becomes a static checkmark graphic
  • A dropdown selection becomes plain text at the same position
  • Annotations and sticky notes become part of the page content

Flattening is the correct approach when you have a completed form and want to lock the filled values. Permissions alone do not prevent a determined user from clearing form fields. Flattening removes the fields entirely.

Use PDF4.dev's Flatten PDF tool or the qpdf command:

qpdf --flatten-annotations=all input.pdf flattened.pdf

Flattening does not protect body text. A PDF editor can still modify text that was always part of the page. Combine flattening with permissions for the broadest coverage.

Watermarks as a deterrent layer

A watermark adds a visible text overlay (such as "Confidential", "Draft", or "Do not distribute") across every page. Watermarks do not block any action. They serve two purposes:

  1. Attribution: the watermark identifies the document owner or intended audience
  2. Deterrence: a recipient is less likely to redistribute a document with a "Confidential" stamp

Use PDF4.dev's Watermark PDF tool to add a text watermark. For the strongest protection, apply the watermark, then flatten the result so the watermark text cannot be removed as a separate layer, then set permissions to restrict further editing.

Watermark PdfTry it free

Choosing the right combination

Use casePermissionsFlattenWatermark
Signed contract sent to a clientYesNoOptional
Completed tax form for recordsOptionalYesNo
Published report for distributionYesNoYes
Invoice delivered to a customerYesNoNo
Internal draft for reviewNoNoYes
Filled application form (final)YesYesNo

For maximum protection: apply all three. Flatten form fields, add a watermark, then set permissions with a strong owner password.

Comparing methods

MethodEncryptionGranular flagsCostAutomation-friendly
PDF4.dev Protect PDFRC4-128No (all-or-nothing)FreeNo (manual)
qpdfAES-256YesFreeYes (CLI)
PyMuPDFAES-256Yes (bitmask)FreeYes (Python)
GhostscriptAES-128/256Yes (bitmask)FreeYes (CLI)
Adobe AcrobatAES-256Yes (GUI)PaidNo (manual)

For automated pipelines (generating restricted PDFs from templates), qpdf or PyMuPDF are the best options. For one-off files, PDF4.dev's browser tool is the fastest path.

What PDF permissions cannot prevent

Be explicit about the limits so you set the right expectations:

  • Screenshots and photos: a reader can always capture the screen
  • OCR re-extraction: printing to image and running OCR recovers text regardless of copy restrictions
  • Third-party tools: open-source libraries can ignore permission flags entirely
  • Retyping: a human can always retype content manually
  • PDF/A compliance: the PDF/A specification forbids encryption, so archival PDFs cannot carry permissions

Permissions are a policy enforced by cooperating software. They deter casual modification and satisfy most business requirements, but they are not tamper-proof.

Generating pre-restricted PDFs with PDF4.dev

If you generate PDFs programmatically (invoices, contracts, reports), you can apply restrictions as a post-processing step. PDF4.dev renders the PDF from an HTML template, and you pipe the output through qpdf before delivery.

# Generate with PDF4.dev API, then restrict with qpdf
curl -s -X POST https://pdf4.dev/api/v1/render \
  -H "Authorization: Bearer p4_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{"template_id": "invoice", "data": {"number": "INV-042"}}' \
  -o /tmp/invoice.pdf
 
qpdf --encrypt "" "owner-secret" 256 \
  --print=full --modify=none --extract=n \
  -- /tmp/invoice.pdf /tmp/invoice-restricted.pdf

This two-step approach gives you full control over which permissions to set per document type.

PDF4.dev generates PDFs from HTML templates with a single API call. Try the template editor to create invoices, contracts, or reports, then restrict them before delivery.

FAQ

How do I make a PDF non-editable for free?

Use PDF4.dev's Protect PDF tool to set a permissions password that disables editing. The tool is free, runs in your browser, and your file never leaves your device. For filled forms, use the Flatten PDF tool to convert field values into static text.

What is the difference between an owner password and a user password?

A user password (open password) blocks opening the file entirely. An owner password (permissions password) lets anyone open the file but restricts what they can do: edit, copy text, print, or fill forms. You can set both on the same PDF.

Can PDF editing restrictions be bypassed?

Yes. PDF permissions are enforced by the viewer application, not by cryptography. Adobe Acrobat and Chrome respect them, but many third-party tools and open-source libraries can ignore the permission flags and modify the document directly. Permissions are a deterrent, not a guarantee.

Does flattening a PDF prevent editing?

Flattening converts interactive elements (form fields, annotations, comments) into static page content. The visual result is identical, but there are no editable fields left. Text in the page body can still be edited with PDF editing software unless you also set permissions.

Can I prevent someone from copying text from a PDF?

A permissions password can disable text selection and copy in viewers that respect PDF permissions. However, OCR or screenshots can still extract the content. No PDF setting can fully prevent a determined reader from copying text.

Is a watermark enough to prevent PDF misuse?

A watermark does not prevent editing or copying. It is a visual deterrent that marks the document as owned, confidential, or draft. Combine a watermark with permissions and flattening for the strongest protection available in the PDF format.

How do I lock a filled PDF form so the answers cannot be changed?

Flatten the PDF. Flattening converts every form field value into static text drawn on the page. The original interactive fields are removed entirely. Use PDF4.dev's Flatten PDF tool or the command qpdf --flatten-annotations=all input.pdf flattened.pdf.

Do PDF permissions affect the file content or layout?

No. Permissions only control what operations a viewer allows. The text, images, fonts, and layout are unchanged. The file size may increase slightly because the permissions password adds an encryption dictionary to the file structure.

Free tools mentioned:

Protect PdfTry it freeWatermark PdfTry it freeFlatten PdfTry it freeMetadata PdfTry it freeCompress PdfTry it free

Start generating PDFs

Build PDF templates with a visual editor. Render them via API from any language in ~300ms.