Unofficial Content

Restrict permissions / protect document (ManagePermissions)

Objective

Apply a user password and a list of permissions to a PDF document (for example, allowing or disallowing printing, content copying, modification, etc.), generating a new protected file.

Parameters

Parameter Required Description
Source path Yes PDF file to protect.
Destination path Yes Path where the protected PDF file will be generated.
User password Yes (can be empty) Password required to open/read the resulting document. If left empty, the resulting document will not prompt for a password to open (permissions are still respected).
Permissions Yes PDFToolsPermission object with a RestrictPermissions switch (boolean) and one boolean property per permission in the predefined catalog (see below).

Catalog of available permissions

  • Allow printing
  • Allow low-quality printing
  • Allow content modification
  • Allow content copying
  • Allow modifying annotations/forms
  • Allow use by screen readers (accessibility)
  • Allow document assembly

Result

Operation status (Error / ErrorMessage) via PDFToolsStatus.

Functional details

  • The source document must not already be protected/encrypted. This functionality does not support unlocking or re-modifying the permissions of a previously protected document: if the source file is already protected, the operation fails with an explicit error. To change the permissions applied to a document, a new file must be generated from its original, unprotected source.

  • How RestrictPermissions works: while it remains false (its default value) — even if no permissions object is passed at all — there is no intent to restrict anything: the resulting document is protected with the given password but with all permissions enabled. Only when RestrictPermissions = true are the individual permissions honored literally: those set to true remain enabled, and those set to false (explicit or untouched) remain denied.

  • To restrict permissions (for example, denying printing and copying while leaving the rest enabled, or denying absolutely all of them), setting RestrictPermissions = true is essential; otherwise, any value set on the individual permissions is ignored and the document ends up with all permissions enabled.

  • "Allow printing" and "Allow low-quality printing" are two independent permissions (as defined by the PDF standard): the first enables printing at any quality, the second enables printing only at low resolution. To fully block printing, both must be set to false; leaving either one true (for example, only "Allow low-quality printing"), the viewer may still offer the print option, even if only at reduced quality.

  • Permission-based PDF protection is not a tamper-proof restriction: the PDF standard relies on the viewer used to open the file honoring those permissions; it is common for different viewers or other tools to behave differently given the same set of permissions.

Usage examples

Protect a document only with a password, without restricting any permission (all enabled):

&PDFFileSource        = "C:\Documents\report.pdf"
&PDFFileTarget        = "C:\Documents\protectedReport.pdf"
&PDFPassword          = "Secret123"

&PDFToolsPermission.RestrictPermissions = false

&PDFToolsStatus = &PdfToolsUtils.ManagePermissions(&PDFFileSource,&PDFFileTarget,&PDFPassword,&PDFToolsPermission)

Protect a document denying printing and copying, allowing the rest (no password):

&PDFFileSource        = "C:\Documents\report.pdf"
&PDFFileTarget        = "C:\Documents\protectedReport.pdf"

&PDFToolsPermission.RestrictPermissions = true

    &PDFToolsPermission.AllowAssembly         = true
    &PDFToolsPermission.AllowCopy            = false
    &PDFToolsPermission.AllowDegradedPrinting = false
    &PDFToolsPermission.AllowFillIn          = true
    &PDFToolsPermission.AllowModifyAnnotations = true
    &PDFToolsPermission.AllowModifyContents  = true
    &PDFToolsPermission.AllowPrinting        = false
    &PDFToolsPermission.AllowScreenReaders   = true

&PDFToolsStatus = &PdfToolsUtils.ManagePermissions(&PDFFileSource,&PDFFileTarget,&PDFPassword,&PDFToolsPermission)

Protect a document denying printing and copying, allowing the rest (with password):

&PDFFileSource        = "C:\Documents\report.pdf"
&PDFFileTarget        = "C:\Documents\protectedReport.pdf"
&PDFPassword          = "Secret123"

&PDFToolsPermission.RestrictPermissions = true

    &PDFToolsPermission.AllowAssembly         = true
    &PDFToolsPermission.AllowCopy            = false
    &PDFToolsPermission.AllowDegradedPrinting = false
    &PDFToolsPermission.AllowFillIn          = true
    &PDFToolsPermission.AllowModifyAnnotations = true
    &PDFToolsPermission.AllowModifyContents  = true
    &PDFToolsPermission.AllowPrinting        = false
    &PDFToolsPermission.AllowScreenReaders   = true

&PDFToolsStatus = &PdfToolsUtils.ManagePermissions(&PDFFileSource,&PDFFileTarget,&PDFPassword,&PDFToolsPermission)

Error and warning messages

Situation Type Message / behavior
The source file is already protected/encrypted Error "The source file is already protected/encrypted. This functionality does not support modifying the permissions of an already protected document; a new file must be generated from its original, unprotected source."
The source file does not exist or is corrupted Error Message describing the problem reading the file.
Last update: 2026 | © GeneXus. All rights reserved. GeneXus Powered by Globant