`;
previewContainer.appendChild(previewItem);
}
// Remove image from preview
function removeImage(id) {
uploadedImages = uploadedImages.filter(img => img.id !== id);
updatePreviewContainer();
updateConvertButton();
}
// Update preview container
function updatePreviewContainer() {
previewContainer.innerHTML = '';
uploadedImages.forEach(displayPreview);
}
// Update convert button state
function updateConvertButton() {
convertBtn.disabled = uploadedImages.length === 0;
}
// Format file size
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
// Handle PDF conversion
async function convertToPDF() {
const useOriginalSize = document.getElementById('originalSize').checked;
const addWatermark = document.getElementById('addWatermark').checked;
if (uploadedImages.length === 0) {
alert('Please upload at least one image.');
return;
}
status.textContent = 'Converting...';
progressBar.style.display = 'block';
progress.style.width = '0%';
try {
// Create PDF document
const pdfDoc = await PDFLib.PDFDocument.create();
// Process each image sequentially
for (let i = 0; i < uploadedImages.length; i++) {
const img = uploadedImages[i];
status.textContent = `Processing image ${i + 1} of ${uploadedImages.length}...`;
try {
// Load image and get its dimensions
const tempImg = await loadImage(img.data);
// Extract the base64 data
const base64Data = img.data.split(',')[1];
const imageBytes = new Uint8Array(atob(base64Data).split('').map(char => char.charCodeAt(0)));
// Embed the image based on its type
let pdfImage;
try {
if (img.data.includes('data:image/jpeg') || img.data.includes('data:image/jpg')) {
pdfImage = await pdfDoc.embedJpg(imageBytes);
} else {
// For non-JPEG images, convert to PNG
const canvas = document.createElement('canvas');
canvas.width = tempImg.width;
canvas.height = tempImg.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(tempImg, 0, 0);
const pngData = canvas.toDataURL('image/png').split(',')[1];
const pngBytes = new Uint8Array(atob(pngData).split('').map(char => char.charCodeAt(0)));
pdfImage = await pdfDoc.embedPng(pngBytes);
}
} catch (embedError) {
console.error('Error embedding image:', embedError);
// Fallback to PNG conversion
const canvas = document.createElement('canvas');
canvas.width = tempImg.width;
canvas.height = tempImg.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(tempImg, 0, 0);
const pngData = canvas.toDataURL('image/png').split(',')[1];
const pngBytes = new Uint8Array(atob(pngData).split('').map(char => char.charCodeAt(0)));
pdfImage = await pdfDoc.embedPng(pngBytes);
}
// Calculate page size
let pageWidth, pageHeight;
if (useOriginalSize) {
pageWidth = tempImg.width;
pageHeight = tempImg.height;
} else {
// A4 size in points (72 points per inch)
pageWidth = 595.276;
pageHeight = 841.890;
}
// Add page to PDF
const page = pdfDoc.addPage([pageWidth, pageHeight]);
// Calculate image dimensions to maintain aspect ratio
let imgWidth = pageWidth;
let imgHeight = (pdfImage.height * pageWidth) / pdfImage.width;
if (imgHeight > pageHeight) {
imgHeight = pageHeight;
imgWidth = (pdfImage.width * pageHeight) / pdfImage.height;
}
// Center the image on the page
const x = (pageWidth - imgWidth) / 2;
const y = (pageHeight - imgHeight) / 2;
// Draw the image
page.drawImage(pdfImage, {
x,
y,
width: imgWidth,
height: imgHeight,
});
// Add watermark if enabled
if (addWatermark) {
page.drawText('CyberKendra.com', {
x: pageWidth - 150,
y: 30,
size: 12,
color: PDFLib.rgb(0.5, 0.5, 0.5),
opacity: 0.7,
});
}
// Update progress
progress.style.width = `${((i + 1) / uploadedImages.length) * 100}%`;
} catch (imageError) {
console.error(`Error processing image ${i + 1}:`, imageError);
status.textContent = `Error processing image ${i + 1}. Continuing with remaining images...`;
continue; // Continue with next image if one fails
}
}
// Save and download the PDF
status.textContent = 'Generating PDF...';
const pdfBytes = await pdfDoc.save();
download(pdfBytes, 'converted-images-cyberkendra.com.pdf', 'application/pdf');
status.textContent = 'Conversion completed! PDF has been downloaded.';
} catch (error) {
console.error('PDF conversion failed:', error);
status.textContent = 'Conversion failed. Please try again.';
} finally {
setTimeout(() => {
progressBar.style.display = 'none';
progress.style.width = '0%';
}, 2000);
}
}
// Reset the tool
function resetTool() {
fileInput.value = '';
previewContainer.innerHTML = '';
uploadedImages = [];
status.textContent = '';
progressBar.style.display = 'none';
progress.style.width = '0%';
updateConvertButton();
}
// Event listeners
fileInput.addEventListener('change', handleFiles);
convertBtn.addEventListener('click', convertToPDF);
resetBtn.addEventListener('click', resetTool);
// Drag and drop handlers
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropZone.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false);
});
['dragenter', 'dragover'].forEach(eventName => {
dropZone.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropZone.addEventListener(eventName, unhighlight, false);
});
dropZone.addEventListener('drop', handleFiles, false);
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
function highlight(e) {
dropZone.classList.add('dragover');
}
function unhighlight(e) {
dropZone.classList.remove('dragover');
}
Image to PDF Converter: A Free Online Tool to Convert Multiple Images to PDF
In today’s digital age, converting images to PDF format has become a common
necessity. Whether you’re creating a documentation portfolio, preserving
digital memories, or preparing professional presentations, having the ability
to convert images to PDF format efficiently is crucial.
Today, we’re introducing a powerful, free online tool that makes this process
seamless and professional: the Image to PDF Converter.
What Makes This Tool Special?
Our
Image to PDF Converter
stands out from other conversion tools due to its combination of powerful
features and user-friendly interface.
Built with modern web technologies and designed with user experience in mind,
this tool offers capabilities that typically come with premium software – all
for free and accessible right from your web browser.
Key Features
1. Multiple Image Support
Upload multiple images simultaneously
Support for various image formats (JPG, JPEG, PNG, GIF, BMP,
WEBP, TIFF)
Easy drag-and-drop interface
Visual preview of all uploaded images
2. Flexible Output Options
Choose between the original image size or the standard A4
format
Option to add professional watermark
High-quality output preservation
InPidual page handling for each image
3. User-Friendly Interface
Clean, Material Design-inspired layout
Real-time conversion progress indicator
Preview functionality before conversion
Simple image management with delete options
How to Use the Tool
Converting your images to PDF is a straightforward process:
1. Upload Your Images
Click the “Upload Images” button or drag and drop your files
The tool accepts multiple images in various formats
Preview thumbnails appear instantly
2. Customize Your Settings
Choose whether to maintain original image dimensions or convert
to A4 size
Enable/disable the watermark option
Review and remove any unwanted images from the selection
3. Convert and Download
Click the “Convert to PDF” button
Watch the progress bar for the conversion status
Download your PDF automatically when complete
Technical Capabilities
Behind its simple interface, the tool packs sophisticated technical features:
Advanced Image Processing: Maintains image quality during conversion
while optimizing file size
Smart Page Handling: Automatically adjusts image placement for
optimal viewing
Format Compatibility: Handles various image formats through
intelligent format detection
Memory Optimization: Processes images sequentially for reliable
performance
Error Recovery: Continues processing even if individual images fail
to convert
This tool proves invaluable in numerous scenarios:
Professional Documentation: Create PDF portfolios from multiple
product photos or design mockups
Academic Use: Compile research images or diagrams into a single PDF
document
Personal Projects: Convert photos into a PDF album or create digital
scrapbooks
Business Presentations: Transform multiple charts or graphs into a
professional PDF report
Privacy and Security
We understand the importance of data security. The tool processes all
conversions directly in your browser – your images never leave your device.
This ensures:
Complete privacy of your content
No server-side storage of your files
Faster conversion process
No internet bandwidth usage for file transfer
Tips for Best Results For best results, process your images in
high quality and ensure clear resolution before converting to PDF.
Our Image to PDF Converter tool combines powerful functionality with ease of
use, making it an essential tool for anyone needing to convert images to PDF
format. Whether you’re a professional needing to create documented portfolios
or a student compiling research materials, this tool provides a reliable,
high-quality solution.
The best part? It’s completely free and requires no installation or sign-up.
Simply
visit the website, upload your images, and convert them to professional-quality PDFs in
seconds.
Give it a try today and experience the convenience of modern image-to-PDF
conversion. Start converting your images to PDF format professionally and
efficiently.
*This tool is maintained by CyberKendra.com, providing free, reliable tools
for digital document management.*