pdf_encrypt
Add password protection to PDF files with user and owner passwords to control access and editing permissions using RC4 128-bit encryption.
Instructions
Encrypt a PDF with password protection (RC4 128-bit). Requires a user password to open. Owner password controls editing permissions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absolute path to the source PDF file | |
| outputPath | Yes | Absolute path for the encrypted output PDF | |
| userPassword | Yes | Password required to open the PDF | |
| ownerPassword | No | Password for editing permissions. Defaults to userPassword if omitted. |
Implementation Reference
- src/tools/manipulate.ts:255-320 (handler)Handler implementation and tool registration for 'pdf_encrypt'.
server.registerTool( "pdf_encrypt", { description: "Encrypt a PDF with password protection (RC4 128-bit). Requires a user password to open. Owner password controls editing permissions.", inputSchema: z .object({ filePath: z .string() .max(4096) .describe("Absolute path to the source PDF file"), outputPath: z .string() .max(4096) .describe("Absolute path for the encrypted output PDF"), userPassword: z .string() .min(1) .max(128) .describe("Password required to open the PDF"), ownerPassword: z .string() .max(128) .optional() .describe( "Password for editing permissions. Defaults to userPassword if omitted." ), }) .strict(), annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }, async ({ filePath, outputPath, userPassword, ownerPassword }) => { try { const resolvedPath = await validatePdfPath(filePath); await validateFileSize(resolvedPath); const resolvedOutput = await validateOutputPath(outputPath, filePath); const buffer = await readFile(resolvedPath); const pdfBytes = toUint8Array(buffer); const encryptedBytes = await encryptPDF( pdfBytes, userPassword, ownerPassword ?? null ) as unknown as Uint8Array; await writeFile(resolvedOutput, encryptedBytes); const fileSize = await getFileSize(resolvedOutput); return toolSuccess({ outputPath: resolvedOutput, encrypted: true, fileSize, }); } catch (error) { return toolError( error instanceof Error ? error.message : String(error) ); } } );