npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pdfsmaller/pdf-encrypt

v1.0.2

Published

Full-featured PDF encryption with AES-256 and RC4 128-bit support. Built for browsers, Node.js, and edge environments. Powers PDFSmaller.com's encryption.

Readme

@pdfsmaller/pdf-encrypt

Full-featured PDF encryption with AES-256 and RC4 128-bit support. Built for browsers, Node.js 18+, Cloudflare Workers, and Deno.

Powers PDFSmaller.com's Protect PDF tool.

Features

  • AES-256 encryption (V=5, R=6) — PDF 2.0 standard, maximum security
  • RC4 128-bit encryption (V=2, R=3) — legacy compatibility mode
  • Granular permissions — control printing, copying, modifying, and more
  • User + Owner passwords — separate passwords for opening and managing PDFs
  • Web Crypto API — no native dependencies, works everywhere
  • Lightweight — ~15KB total (crypto + encryption logic)
  • Zero dependencies — only pdf-lib as a peer dependency
  • TypeScript types included

Installation

npm install @pdfsmaller/pdf-encrypt pdf-lib

Quick Start

import { encryptPDF } from '@pdfsmaller/pdf-encrypt';
import fs from 'fs';

const pdfBytes = fs.readFileSync('input.pdf');

// AES-256 encryption (default, recommended)
const encrypted = await encryptPDF(new Uint8Array(pdfBytes), 'my-password');
fs.writeFileSync('encrypted.pdf', encrypted);

API

encryptPDF(pdfBytes, userPassword, options?)

| Parameter | Type | Description | |-----------|------|-------------| | pdfBytes | Uint8Array | The PDF file as bytes | | userPassword | string | Password required to open the PDF | | options | object | Optional configuration (see below) |

Returns: Promise<Uint8Array> — The encrypted PDF bytes

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | ownerPassword | string | same as user | Password for managing permissions | | algorithm | 'AES-256' \| 'RC4' | 'AES-256' | Encryption algorithm | | allowPrinting | boolean | true | Allow printing the document | | allowModifying | boolean | true | Allow modifying content | | allowCopying | boolean | true | Allow copying text/images | | allowAnnotating | boolean | true | Allow adding annotations | | allowFillingForms | boolean | true | Allow form filling | | allowExtraction | boolean | true | Allow accessibility extraction | | allowAssembly | boolean | true | Allow document assembly | | allowHighQualityPrint | boolean | true | Allow high-quality printing |

Examples

Restrict Permissions

const encrypted = await encryptPDF(pdfBytes, 'user-pass', {
  ownerPassword: 'admin-pass',
  allowPrinting: true,
  allowCopying: false,
  allowModifying: false
});

RC4 Legacy Mode

const encrypted = await encryptPDF(pdfBytes, 'password', {
  algorithm: 'RC4'
});

Browser Usage

<input type="file" id="pdf-input" accept=".pdf" />
<script type="module">
  import { encryptPDF } from '@pdfsmaller/pdf-encrypt';

  document.getElementById('pdf-input').addEventListener('change', async (e) => {
    const file = e.target.files[0];
    const pdfBytes = new Uint8Array(await file.arrayBuffer());
    const encrypted = await encryptPDF(pdfBytes, 'secret');

    // Download
    const blob = new Blob([encrypted], { type: 'application/pdf' });
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'encrypted.pdf';
    a.click();
  });
</script>

AES-256 vs RC4

| Feature | AES-256 | RC4 | |---------|---------|-----| | Security | Quantum-resistant | Deprecated, known weaknesses | | PDF Version | 2.0 (ISO 32000-2) | 1.4+ (ISO 32000-1) | | Key Length | 256-bit | 128-bit | | Reader Support | Modern readers | All readers | | Recommended | Yes | Legacy only |

Related Packages

| Package | Description | |---------|-------------| | @pdfsmaller/pdf-decrypt | Full decryption — AES-256 + RC4 (companion to this package) | | @pdfsmaller/pdf-encrypt-lite | Lightweight RC4-only encryption (~7KB) | | @pdfsmaller/pdf-decrypt-lite | Lightweight RC4-only decryption (~8KB) |

License

MIT — PDFSmaller.com