2x5 Button Grid
Age Calculator |
Button 2 |
Button 3 |
Button 4 |
Button 5 |
Button 6 |
Button 7 |
Button 8 |
Button 9 |
Button 10 |
PDF Compressor
PDF Compressor
body, html {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
.container {
width: 50%;
margin: auto;
overflow: hidden;
padding: 20px;
text-align: center;
background: #fff;
margin-top: 50px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
}
h1 {
font-size: 24px;
margin-bottom: 20px;
}
.upload-section, .download-section {
margin: 20px 0;
}
#file-input {
margin-bottom: 10px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
background-color: #0779e4;
color: white;
border-radius: 5px;
}
button:disabled {
background-color: #ccc;
}
#status-message {
margin-top: 20px;
}
function uploadFile() {
const fileInput = document.getElementById('file-input');
const file = fileInput.files[0];
const statusMessage = document.getElementById('status-message');
if (!file) {
alert('Please select a PDF file to upload.');
return;
}
const formData = new FormData();
formData.append('file', file);
statusMessage.textContent = 'Uploading and compressing...';
// Simulating a file upload and compression
// This is where you would normally use an AJAX request to send the file to the server
setTimeout(() => {
statusMessage.textContent = 'File compressed successfully!';
document.querySelector('.download-section').style.display = 'block';
}, 2000); // Simulating server response time
}
function downloadFile() {
// This function would normally download the compressed file from the server
// For demo purposes, we'll simulate a download
alert('Download started!');
// Simulate a download by redirecting to a sample PDF (replace with actual download link)
window.location.href = 'sample-compressed.pdf';
}
const express = require('express');
const fileUpload = require('express-fileupload');
const { PDFDocument } = require('pdf-lib');
const fs = require('fs');
const app = express();
const port = 3000;
app.use(fileUpload());
app.use(express.static('public'));
app.post('/upload', async (req, res) => {
if (!req.files || Object.keys(req.files).length === 0) {
return res.status(400).send('No files were uploaded.');
}
const pdfFile = req.files.file;
// Load PDF document
const pdfDoc = await PDFDocument.load(pdfFile.data);
const pages = pdfDoc.getPages();
// Set PDF compression
for (const page of pages) {
page.setOpacity(0.95); // Reduce opacity to simulate compression
}
// Save the compressed PDF
const compressedPdfBytes = await pdfDoc.save();
fs.writeFileSync(__dirname + '/public/compressed.pdf', compressedPdfBytes);
res.send('File compressed and saved!');
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});