Skip to main content
Glama

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
NameRequiredDescriptionDefault
filePathYesAbsolute path to the source PDF file
outputPathYesAbsolute path for the encrypted output PDF
userPasswordYesPassword required to open the PDF
ownerPasswordNoPassword for editing permissions. Defaults to userPassword if omitted.

Implementation Reference

  • 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)
          );
        }
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AryanBV/pdf-toolkit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server