Client-side

UNLOCK PDF

Remove password security and permission restrictions from your PDF document instantly. Must know the password to unlock.

🔓
Drag & drop a locked PDF file here, or click to browse
Supports single encrypted .pdf file

About Unlock PDF Tool

Remove security restrictions and passwords from your PDF files to make them easily accessible. If you have the password, this tool decrypts the file and saves an unlocked copy. Perfect for removing passwords from statements or invoices you need to archive.

Decryption happens completely client-side in your browser. Your password and files remain on your device, ensuring maximum confidentiality.

Developer Reference

Core Algorithm & Standalone Script

Standalone, zero-dependency JavaScript implementation powering this tool. Free to inspect, copy, and build upon.

import { decryptPDF, isEncrypted } from 'https://cdn.jsdelivr.net/npm/@pdfsmaller/pdf-decrypt@1.0.1/+esm';

    let currentPdfBytes = null;
    let fileNameStr = '';

    const uploadZone = document.getElementById('uploadZone');
    const fileInput = document.getElementById('fileInput');
    const configPanel = document.getElementById('configPanel');
    const fileNameEl = document.getElementById('fileName');
    const encryptInfoEl = document.getElementById('encryptInfo');
    const pdfPasswordInput = document.getElementById('pdfPassword');
    const unlockBtn = document.getElementById('unlockBtn');
    const loadingContainer = document.getElementById('loadingContainer');
    const resultContainer = document.getElementById('resultContainer');
    const resultInfo = document.getElementById('resultInfo');
    const downloadBtn = document.getElementById('downloadBtn');

    // Drag and drop event listeners
    ['dragenter', 'dragover'].forEach(eventName => {
      uploadZone.addEventListener(eventName, e => {
        e.preventDefault();
        uploadZone.classList.add('dragover');
      }, false);
    });

    ['dragleave', 'drop'].forEach(eventName => {
      uploadZone.addEventListener(eventName, e => {
        e.preventDefault();
        uploadZone.classList.remove('dragover');
      }, false);
    });

    uploadZone.addEventListener('drop', e => {
      const dt = e.dataTransfer;
      const files = dt.files;
      if (files.length > 0) handleFile(files[0]);
    });

    fileInput.addEventListener('change', e => {
      if (e.target.files.length > 0) handleFile(e.target.files[0]);
    });

    async function handleFile(file) {
      if (file.type !== 'application/pdf') return;
      fileNameStr = file.name;

      try {
        currentPdfBytes = await file.arrayBuffer();
        const info = await isEncrypted(new Uint8Array(currentPdfBytes));

        if (!info.encrypted) {
          alert('This PDF is not password-protected. No decryption is needed.');
          return;
        }

        fileNameEl.textContent = file.name;
        encryptInfoEl.textContent = `LOCKED (${info.algorithm})`;
        
        configPanel.classList.remove('hidden');
        resultContainer.classList.add('hidden');
      } catch (err) {
        console.error(err);
        alert('Could not parse file as PDF.');
      }
    }

    function formatBytes(bytes, decimals = 2) {
      if (bytes === 0) return '0 Bytes';
      const k = 1024;
      const dm = decimals < 0 ? 0 : decimals;
      const sizes = ['Bytes', 'KB', 'MB', 'GB'];
      const i = Math.floor(Math.log(bytes) / Math.log(k));
      return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
    }

    unlockBtn.addEventListener('click', async () => {
      if (!currentPdfBytes) return;

      const password = pdfPasswordInput.value;
      if (!password) {
        alert('Please enter the PDF password to unlock.');
        return;
      }

      configPanel.classList.add('hidden');
      loadingContainer.classList.remove('hidden');
      resultContainer.classList.add('hidden');

      try {
        const decryptedBytes = await decryptPDF(new Uint8Array(currentPdfBytes), password);
        const blob = new Blob([decryptedBytes], { type: 'application/pdf' });
        const blobUrl = URL.createObjectURL(blob);

        downloadBtn.href = blobUrl;
        const nameWithoutExt = fileNameStr.replace(/\.[^/.]+$/, "");
        downloadBtn.download = `${nameWithoutExt}_unlocked.pdf`;
        resultInfo.textContent = `Password removed. Decrypted PDF size: ${formatBytes(blob.size)}.`;

        loadingContainer.classList.add('hidden');
        resultContainer.classList.remove('hidden');
      } catch (err) {
        console.error(err);
        alert('Decryption failed. Please ensure the password is correct.');
        loadingContainer.classList.add('hidden');
        configPanel.classList.remove('hidden');
      }
    });