MCPcopy Create free account
hub / github.com/LibPDF-js/core / setProtection

Method setProtection

src/api/pdf.ts:986–998  ·  view source on GitHub ↗

* Add or change document encryption. * * If the document is already encrypted, requires owner access to change. * If unencrypted, can be called without restrictions. * * @param options - Protection options (passwords, permissions, algorithm) * @throws {PermissionDeniedError} If ins

(options: ProtectionOptions)

Source from the content-addressed store, hash-verified

984 * ```
985 */
986 setProtection(options: ProtectionOptions): void {
987 // If encrypted, need owner access to change
988 if (this.isEncrypted) {
989 const handler = this.ctx.info.securityHandler;
990
991 if (handler && !handler.hasOwnerAccess) {
992 throw new PermissionDeniedError("Cannot change protection: requires owner access");
993 }
994 }
995
996 // Mark that encryption should be applied on save
997 this._pendingSecurity = { action: "encrypt", options };
998 }
999
1000 // ─────────────────────────────────────────────────────────────────────────────
1001 // Metadata

Callers 2

mainFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected