• 27 Jun, 2025

Create a PDF Password Maker with HTML, CSS & JavaScript (Using PDF.co API)

Create a PDF Password Maker with HTML, CSS & JavaScript (Using PDF.co API)

Create a secure PDF Password Maker using HTML, CSS, and JavaScript with PDF.co API. Add user and owner passwords, AES128 encryption, drag & drop upload, and instant download. Learn how to build this modern, responsive web app with easy-to-follow code examples.

What You’ll Build

A web-based tool that allows users to:

  • Upload or drag-and-drop a PDF file
  • Set a user and owner password
  • Encrypt the file using AES128 encryption
  • Instantly download the secured PDF

 

Key Features

Drag & Drop Upload
AES128 PDF Encryption
User and Owner Password Protection
PDF.co API Integration for Cloud Security
Responsive UI with Modern Design
Instant Download Link

 

Technologies Used

  • HTML5 – Clean, semantic layout
  • CSS3 – Responsive and modern design
  • JavaScript – Handles file uploads, API communication, and UI logic
  • PDF.co API – Cloud-based PDF processing with encryption support

 

📄 Full Source Code:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>PDF Password Maker</title>
  <link rel="stylesheet" href="style.css" />
</head>
<body>
  <div class="container">
    <h1>🔐 PDF Password Maker</h1>
    <form id="pdfForm">
      <div class="drop-zone" id="dropZone">
        <p>📁 Drag & Drop PDF or <label for="fileInput" class="browse-btn">Browse</label></p>
        <input type="file" id="fileInput" accept="application/pdf" hidden />
      </div>

      <input type="password" id="userPassword" placeholder="User Password" required />
      <input type="password" id="ownerPassword" placeholder="Owner Password" required />
      <button type="submit">Protect PDF</button>
    </form>

    <div id="downloadSection" style="display: none;">
      <p>✅ PDF protected! <a id="downloadLink" href="#" download>Download here</a></p>
    </div>
  </div>

  <script src="script.js"></script>
</body>
</html>

 

style.css

body {
  font-family: Arial, sans-serif;
  background: #f0f4f8;
  display: flex;
  justify-content: center;
  padding: 40px;
}
.container {
  background: white;
  padding: 30px;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 500px;
  text-align: center;
}
h1 {
  margin-bottom: 20px;
}
.drop-zone {
  border: 2px dashed #ccc;
  padding: 30px;
  border-radius: 12px;
  margin-bottom: 20px;
  background-color: #fafafa;
  cursor: pointer;
}
.browse-btn {
  color: #007bff;
  cursor: pointer;
  text-decoration: underline;
}
input[type="password"] {
  width: 100%;
  padding: 12px;
  margin: 10px 0;
  border-radius: 8px;
  border: 1px solid #ccc;
}
button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
}
button:hover {
  background-color: #0056b3;
}

 

script.js

const form = document.getElementById('pdfForm');
const fileInput = document.getElementById('fileInput');
const dropZone = document.getElementById('dropZone');
const downloadSection = document.getElementById('downloadSection');
const downloadLink = document.getElementById('downloadLink');

let selectedFile = null;

// Drag & drop events
dropZone.addEventListener('click', () => fileInput.click());
dropZone.addEventListener('dragover', (e) => {
  e.preventDefault();
  dropZone.style.borderColor = "#007bff";
});
dropZone.addEventListener('dragleave', () => {
  dropZone.style.borderColor = "#ccc";
});
dropZone.addEventListener('drop', (e) => {
  e.preventDefault();
  dropZone.style.borderColor = "#ccc";
  selectedFile = e.dataTransfer.files[0];
});

// Browse file input
fileInput.addEventListener('change', () => {
  selectedFile = fileInput.files[0];
});

form.addEventListener('submit', async (e) => {
  e.preventDefault();

  if (!selectedFile) {
    alert("Please upload a PDF file.");
    return;
  }

  const userPassword = document.getElementById('userPassword').value;
  const ownerPassword = document.getElementById('ownerPassword').value;

  const apiKey = 'YOUR_PDFCO_API_KEY_HERE';
  const formData = new FormData();
  formData.append('name', selectedFile.name);
  formData.append('file', selectedFile);
  formData.append('ownerPassword', ownerPassword);
  formData.append('userPassword', userPassword);
  formData.append('encryptionAlgorithm', 'AES128');

  try {
    const response = await fetch('https://api.pdf.co/v1/pdf/security/add', {
      method: 'POST',
      headers: {
        'x-api-key': apiKey
      },
      body: formData
    });

    const data = await response.json();

    if (data.error) {
      alert('Error: ' + data.message);
    } else {
      downloadSection.style.display = 'block';
      downloadLink.href = data.url;
    }

  } catch (err) {
    console.error(err);
    alert("Something went wrong. Check console for more info.");
  }
});

Notes:

  • Replace 'YOUR_PDFCO_API_KEY_HERE' with your actual API key.
  • This example uses AES128 encryption as specified.
  • PDF.co's API handles all secure file processing.

 

How It Works

  1. The user uploads or drags a PDF file into the web app.
  2. They enter a user password (to open the file) and an owner password (to manage permissions).
  3. On submit, the PDF is securely uploaded to PDF.co’s encryption API.
  4. The response includes a protected PDF URL, ready for download.

 

Security: Why Use AES128?

AES128 is a trusted industry-standard encryption method. It's strong enough for most use cases, providing reliable protection without significantly increasing file size or processing time.

PDF.co ensures:

  • Files are deleted after processing
  • HTTPS secure endpoints
  • AES128/256 support
  • GDPR and HIPAA-compliant handling

 

Tips & Best Practices

  • Never hard-code your API key in public-facing apps. Use a backend proxy for production.
  • Encourage users to set strong passwords (mix of upper/lowercase, numbers, symbols).
  • You can enhance the UI using frameworks like TailwindCSS or Bootstrap.

 

Conclusion

This project is a perfect example of how modern web technologies can create secure, user-friendly tools. By combining HTML, CSS, JavaScript, and cloud APIs, you can offer real-world functionality with minimal effort.

Start protecting your PDFs today — build it, host it, and help users stay safe!

Y2A Post

Discover the innovative work in AI-generated blogs, seamlessly blending technology with creativity. This unique approach not only offers fresh perspectives on various topics but also ensures that content is engaging and relevant.