Transform DOCX documents into professional PDF files instantly. Secure, private, and free.
Drop Word File Here
Supports .docx format
PDF Options
Small (10mm)
Standard (20mm)
None (0mm)
A4
Letter
Legal
Preview Mode: The preview on the right shows how the content was extracted. The final PDF will look similar to this preview.
Privacy Note: Your document is converted locally in your browser. We do not upload your file to any server.
// — JAVASCRIPT SEPARATION START —// DOM Elements
const dropzone = document.getElementById(‘upload-stage’);
const previewStage = document.getElementById(‘preview-stage’);
const fileInput = document.getElementById(‘fileInput’);
const documentContainer = document.getElementById(‘document-container’);
const btnConvert = document.getElementById(‘btn-convert’);
const btnText = document.getElementById(‘btn-text’);
const btnLoader = document.getElementById(‘btn-loader’);
const optMargin = document.getElementById(‘opt-margin’);
const optFormat = document.getElementById(‘opt-format’);let currentFileName = “document”;
let isDarkMode = false;// — Event Listeners —
dropzone.addEventListener(‘click’, () => fileInput.click());
dropzone.addEventListener(‘dragover’, (e) => { e.preventDefault(); dropzone.classList.add(‘dropzone-active’); });
dropzone.addEventListener(‘dragleave’, () => dropzone.classList.remove(‘dropzone-active’));
dropzone.addEventListener(‘drop’, (e) => {
e.preventDefault();
dropzone.classList.remove(‘dropzone-active’);
if(e.dataTransfer.files.length) handleFile(e.dataTransfer.files[0]);
});fileInput.addEventListener(‘change’, (e) => {
if(e.target.files.length) handleFile(e.target.files[0]);
});// Update Preview CSS based on options
optMargin.addEventListener(‘change’, updatePreviewStyle);
// Format change doesn’t change preview size on screen much (it’s css width),
// but html2pdf uses it for generation.// — Core Functions —function handleFile(file) {
if (!file.name.endsWith(‘.docx’)) {
alert(‘Please upload a valid .docx Word file.’);
return;
}currentFileName = file.name.replace(‘.docx’, ”);
// Convert to ArrayBuffer for Mammoth
const reader = new FileReader();
reader.onload = function(e) {
const arrayBuffer = e.target.result;
mammoth.convertToHtml({arrayBuffer: arrayBuffer})
.then(displayResult)
.catch(handleError);
};
reader.readAsArrayBuffer(file);
}function displayResult(result) {
// Inject HTML into preview container
documentContainer.innerHTML = result.value;
// Show Preview Stage
dropzone.classList.add(‘hidden’);
previewStage.classList.remove(‘hidden’);
document.getElementById(‘privacy-note’).classList.add(‘hidden’); // Hide footer note to clean up view
// Check for warnings
if(result.messages.length > 0) {
console.log(“Mammoth messages:”, result.messages);
}
}function handleError(err) {
console.error(err);
alert(“Error reading the Word file. Please try a simple .docx file.”);
}function updatePreviewStyle() {
const margin = optMargin.value + ‘mm’;
documentContainer.style.padding = margin;
}function generatePDF() {
btnConvert.disabled = true;
btnText.innerText = ‘Generating PDF…’;
btnLoader.classList.remove(‘hidden’);// Config for html2pdf
const margin = parseInt(optMargin.value); // mm
const format = optFormat.value;
const opt = {
margin: margin / 25.4, // convert mm to inches roughly, html2pdf takes numbers as inches or array
// Actually html2pdf margin default unit is questionable, let’s rely on arrays [top, left, bot, right]
// Better: use simple number which defaults to 1 = 96px? No, it’s usually in inches or mm based on jsPDF.
// Let’s stick to the library default unit which is usually based on the page size.
// Actually, passing [10, 10, 10, 10] works well for mm in newer versions if jsPDF unit is mm.
margin: margin, // Pass number, often treated as mm in recent html2pdf with jspdf
filename: currentFileName + ‘.pdf’,
image: { type: ‘jpeg’, quality: 0.98 },
html2canvas: { scale: 2, useCORS: true }, // High res scale
jsPDF: { unit: ‘mm’, format: format, orientation: ‘portrait’ }
};// Execution
html2pdf().set(opt).from(documentContainer).save().then(() => {
btnConvert.disabled = false;
btnText.innerText = ‘Download PDF’;
btnLoader.classList.add(‘hidden’);
}).catch(err => {
console.error(err);
alert(“Error generating PDF.”);
btnConvert.disabled = false;
btnText.innerText = ‘Download PDF’;
btnLoader.classList.add(‘hidden’);
});
}function resetApp() {
fileInput.value = ”;
documentContainer.innerHTML = ”;
dropzone.classList.remove(‘hidden’);
previewStage.classList.add(‘hidden’);
document.getElementById(‘privacy-note’).classList.remove(‘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 —
About the Word to PDF tool
The Word to PDF page is part of Articles Stock’s online utilities collection. Use the tool above for the task described in its interface, and check the available file types, settings and output before proceeding. This utility relates to document conversion and PDF workflows.
How to use this tool
Review the tool’s supported input and options.
Select or enter the required input and choose the settings that suit your task.
Run the tool and check the result before saving or sharing it.