Change the permissions of a PDF file.
cargo binstall pdf-permNavigate to the Releases page and download respective binary for your platform. Make sure to give it execute permissions.
cargo install pdf-permThe usage is quite similar to chmod command:
pdf-perm +c no-copy.pdfThis will modify no-copy.pdf and make it copiable. Bugs may arise, so make sure to backup if it matters. Alternatively, by specifying another path, this tool will write to there instead of overwriting the original file:
pdf-perm +c no-copy.pdf can-copy.pdfTo reject a permission, use -:
pdf-perm -c can-copy.pdf no-copy.pdfTo set exactly the permissions you want, use =:
pdf-perm =pma my.pdfThis will set the permissions to PRINTABLE, MODIFIABLE, and ANNOTABLE and reject all other permissions.
To grant all permissions, use +* or =*; to reject all permissions, use -*:
pdf-perm +* confidential.pdf declassified.pdfSome example PDF files are provided in the samples directory. You can use them to test the program.
pdf-perm [PERMISSION] <INPUT> [OUTPUT]| Argument Length | Interpretation |
|---|---|
| 0 | Print help and permissions |
| 1 | <INPUT> |
| 2 | [PERMISSION] <INPUT> |
| 3 | [PERMISSION] <INPUT> [OUTPUT] |
| 4+ | Invalid |
The permission argument is a string that specify the permissions to be set on the PDF file. It must starts with one of the following:
+: to grant permissions-: to reject permissions=: to set permissions exactly
Then, you can specify the short flags for the permissions you want to grant, reject, or set exactly. Valid short flags and their corresponding constant in lopdf crate are:
| # | Short Flag | Constant |
|---|---|---|
| 3 | p |
PRINTABLE |
| 4 | m |
MODIFIABLE |
| 5 | c |
COPYABLE |
| 6 | a |
ANNOTABLE |
| 9 | f |
FILLABLE |
| 10 | x |
COPYABLE_FOR_ACCESSIBILITY |
| 11 | s |
ASSEMBLABLE |
| 12 | q |
PRINTABLE_IN_HIGH_QUALITY |
| / | * |
All permissions |
Note
- The index in the tables are
$1$ -based. - The actual permissions you see on PDF readers may differ from the ones you see using this tool. This is because some permissions imply others.
- See the PDF 1.4 ref, TABLE 3.15 for more details.
If this argument is not specified, pdf-perm will print the permissions of the input file and exit.
Required. Path to the input PDF file. This file will be modified in place unless an output path is specified.
Path to the output PDF file. If not specified, the input file will be modified in place.
When the last part of the argv[0] matches (pdf-)?desec(ure)? (case-insensitive, without extension), the program will run in "DeSec" mode. In this mode, the program will only accept one argument, input file path, asking for it if not provided. The program will then grant all permissions to the PDF file, effectively removing all restrictions.
Typically, you can rename the binary or create a symlink as pdf-desec or desec to enable this mode. In this way, simply dragging and dropping a PDF file onto the binary will remove all restrictions from it.
- This crate does NOT handle password protected PDFs. Consider decrypting them first, or using pdfrip to break the password.
- Currently, only PDF 1.4 is supported.
- abatsakidis/PDFDeSecure, for the inspiration.
- J-F-Liu/lopdf, for the
lopdfcrate, which is used to read and write PDF files.
- Preserve
EncryptionVersion - Allow specifying
EncryptionVersionif not present - Implement
chmodlike syntax (-,+,=) - Extended syntax
-
*for all permissions
-
- DeSec mode
- Set to
Noneif permissions are default