Convert PNG to PDF
Combine your PNG images into a single PDF. Preserves transparency and quality for professional documents.
Drop PNG Images Here
Merge multiple files into one PDF
PDF Settings
Fit to Image
A4 (Standard)
Letter (US)
Portrait
Landscape
Auto (Detect)
No Margin
Small (20px)
Large (50px)
Files (0)
Drag thumbnails to reorder pages
${name}
#
`;
imageGrid.appendChild(div);
updateBadges();
}function removeImage(id) {
const el = document.getElementById(id);
if(el) el.remove();
images = images.filter(img => img.id !== id);
updateCount();
updateBadges();
if(images.length === 0) {
resetApp();
}
}function updateCount() {
fileCountEl.innerText = images.length;
}function updateBadges() {
const items = document.querySelectorAll(‘.image-item’);
items.forEach((item, index) => {
item.querySelector(‘.page-badge’).innerText = index + 1;
});
}async function generatePDF() {
if(images.length === 0) return;btnConvert.disabled = true;
btnText.innerText = ‘Building PDF…’;
btnLoader.classList.remove(‘hidden’);try {
const { PDFDocument, PageSizes } = PDFLib;
const pdfDoc = await PDFDocument.create();// Get Order from DOM
const orderedIds = Array.from(imageGrid.children).map(el => el.id);for (const id of orderedIds) {
const imgData = images.find(img => img.id === id);
if(!imgData) continue;// Embed Image
let image;
const imgBytes = await fetch(imgData.dataUrl).then(res => res.arrayBuffer());
if (imgData.file.type === ‘image/jpeg’ || imgData.file.name.match(/\.(jpg|jpeg)$/i)) {
image = await pdfDoc.embedJpg(imgBytes);
} else {
image = await pdfDoc.embedPng(imgBytes);
}// Determine Page Size
const sizeSetting = pdfSize.value;
const orientation = pdfOrientation.value;
const margin = parseInt(pdfMargin.value);let pageWidth, pageHeight;
if (sizeSetting === ‘fit’) {
pageWidth = image.width + (margin * 2);
pageHeight = image.height + (margin * 2);
} else {
const standard = sizeSetting === ‘a4’ ? PageSizes.A4 : PageSizes.Letter;
let isLandscape = false;
if (orientation === ‘landscape’) isLandscape = true;
else if (orientation === ‘auto’) isLandscape = image.width > image.height;
pageWidth = isLandscape ? standard[1] : standard[0];
pageHeight = isLandscape ? standard[0] : standard[1];
}const page = pdfDoc.addPage([pageWidth, pageHeight]);
const availW = pageWidth – (margin * 2);
const availH = pageHeight – (margin * 2);
let imgW = image.width;
let imgH = image.height;
const scaleW = availW / imgW;
const scaleH = availH / imgH;
const scale = Math.min(scaleW, scaleH, 1);
const drawW = imgW * scale;
const drawH = imgH * scale;page.drawImage(image, {
x: (pageWidth – drawW) / 2,
y: (pageHeight – drawH) / 2,
width: drawW,
height: drawH,
});
}const pdfBytes = await pdfDoc.save();
const blob = new Blob([pdfBytes], { type: ‘application/pdf’ });
const url = URL.createObjectURL(blob);editorStage.classList.add(‘hidden’);
successStage.classList.remove(‘hidden’);
downloadBtn.href = url;
downloadBtn.download = ‘png_combined.pdf’;} catch (err) {
console.error(err);
alert(‘Error creating PDF. Some images might be incompatible.’);
} finally {
btnConvert.disabled = false;
btnText.innerText = ‘Create PDF’;
btnLoader.classList.add(‘hidden’);
}
}function resetApp() {
fileInput.value = ”;
images = [];
imageGrid.innerHTML = ”;
dropzone.classList.remove(‘hidden’);
editorStage.classList.add(‘hidden’);
successStage.classList.add(‘hidden’);
}function toggleDarkMode() {
isDarkMode = !isDarkMode;
document.documentElement.classList.toggle(‘dark’);
const icon = document.getElementById(‘theme-icon’);
if(isDarkMode) {
icon.classList.remove(‘fa-moon’);
icon.classList.add(‘fa-sun’);
} else {
icon.classList.remove(‘fa-sun’);
icon.classList.add(‘fa-moon’);
}
}// — JAVASCRIPT SEPARATION END —PNG to PDF: Overview and Usage Tips
Use the PNG to PDF utility for tasks involving PDF documents. Review the tool interface for supported inputs and settings. For file-based tasks, keep a copy of your original file and check the output before using it.
Steps to get started
- Read the supported formats or input requirements shown in the tool.
- Choose the available options appropriate to your task.
- Run the tool and review its result for accuracy and quality.
Related resources
Related PDF tools: PDF to PNG and Compress PDF. Review the converted file before sharing.