Pular para o conteúdo
Início Juntar PDF Comprimir PDF Ver todas →

🌐 HTML para PDF

Cole seu código HTML, faça upload de um arquivo .html ou informe uma URL para converter em PDF.

Código HTML
📁
Arraste seu arquivo HTML aqui
ou clique para selecionar (.html, .htm)
Selecionar arquivo
🌐
⚠️ A busca usa um proxy público (allorigins.win). Sites com JavaScript pesado ou proteção anti-bot podem não carregar corretamente.
👁️ Pré-visualização
Opções do PDF
Tamanho
Formato da página
Orientação
Retrato ou paisagem
Escala
Zoom do conteúdo
Fundo
Imprimir cores de fundo
Renderizando HTML... 0%
🎉
PDF gerado com sucesso!
⬇️ Baixar PDF
Converter outro HTML
🔗

3 formas de entrada

Cole o código diretamente, faça upload de um arquivo .html ou informe a URL de qualquer página web.

🔒

100% Seguro

Tudo processado no seu navegador. Nenhum arquivo ou código é enviado a servidores externos.

🆓

Totalmente Grátis

Sem cadastro, sem limite de conversões, sem marca d'água no resultado.

Perguntas Frequentes

Cole a URL ou o HTML e clique em "Converter para PDF". O PDF é gerado preservando o layout visual da página.

Sim, preservamos CSS e layout. Animações e conteúdo dinâmico (JavaScript) podem não ser capturados, mas toda a estilização estática é mantida.

Sim, páginas longas são divididas automaticamente em múltiplas páginas no PDF. Use a escala 60% ou 80% para caber mais conteúdo por página.

Sim, 100% gratuito. Sem cadastro, sem limite de conversões e sem marca d'água no PDF gerado.

📖 Quer o passo a passo completo? Leia Como converter HTML para PDF.

', '' ].join('\n'); document.getElementById('html-code').value = sample; showToast('✅ Exemplo carregado!'); } function clearCode() { document.getElementById('html-code').value = ''; document.getElementById('preview-section').classList.remove('show'); document.getElementById('result-box').classList.remove('show'); loadedHTML = ''; } // ─── File upload ────────────────────────────────────────────── function loadHTMLFile(file) { uploadedFile = file; const reader = new FileReader(); reader.onload = e => { loadedHTML = e.target.result; document.getElementById('fl-name').textContent = file.name; document.getElementById('fl-size').textContent = formatBytes(file.size); document.getElementById('file-loaded').classList.add('show'); uploadZone.style.display = 'none'; updatePreviewFromHTML(loadedHTML); }; reader.readAsText(file); } function removeHtmlFile() { uploadedFile = null; loadedHTML = ''; htmlFileInput.value = ''; document.getElementById('file-loaded').classList.remove('show'); uploadZone.style.display = 'block'; document.getElementById('preview-section').classList.remove('show'); } // ─── URL fetch ──────────────────────────────────────────────── async function fetchURL() { const url = document.getElementById('url-input').value.trim(); if (!url || !url.startsWith('http')) { document.getElementById('url-input').classList.add('error'); showToast('⚠️ Informe uma URL válida começando com http://'); return; } document.getElementById('url-input').classList.remove('error'); const btn = document.getElementById('url-fetch-btn'); const status = document.getElementById('url-status'); btn.disabled = true; btn.textContent = '⏳ Buscando...'; status.className = 'url-status show loading'; status.textContent = '⏳ Buscando o HTML da página via proxy...'; try { const proxyURL = 'https://api.allorigins.win/get?url=' + encodeURIComponent(url); const resp = await fetch(proxyURL); if (!resp.ok) throw new Error('Proxy retornou erro'); const data = await resp.json(); if (!data.contents) throw new Error('Conteúdo vazio'); const base = new URL(url); const baseTag = ''; loadedHTML = data.contents.replace(/]*>/i, m => m + baseTag); status.className = 'url-status show ok'; status.textContent = '✅ HTML carregado! (' + formatBytes(loadedHTML.length) + ')'; updatePreviewFromHTML(loadedHTML); } catch (err) { status.className = 'url-status show fail'; status.textContent = '❌ Não foi possível carregar a página. O site pode ter proteção anti-bot ou CORS restrito.'; loadedHTML = ''; } btn.disabled = false; btn.textContent = '🔗 Buscar página'; } // ─── Preview ────────────────────────────────────────────────── function getActiveHTML() { if (currentMode === 'code') return document.getElementById('html-code').value.trim(); return loadedHTML; } function updatePreview() { const html = getActiveHTML(); if (!html) { showToast('⚠️ Digite ou cole algum HTML primeiro.'); return; } updatePreviewFromHTML(html); } function updatePreviewFromHTML(html) { if (!html) return; document.getElementById('preview-frame').srcdoc = html; document.getElementById('preview-section').classList.add('show'); document.getElementById('options-section').classList.add('show'); document.getElementById('result-box').classList.remove('show'); } function togglePreview() { previewVisible = !previewVisible; const frame = document.getElementById('preview-frame'); const toggle = document.querySelector('.preview-toggle'); frame.style.display = previewVisible ? 'block' : 'none'; toggle.textContent = previewVisible ? 'Ocultar prévia' : 'Mostrar prévia'; } // ─── Convert ────────────────────────────────────────────────── async function convertToPDF() { const html = getActiveHTML(); if (!html) { showToast('⚠️ Nenhum conteúdo HTML para converter.'); return; } const btn = document.getElementById('convert-btn'); btn.disabled = true; btn.textContent = '⏳ Convertendo...'; document.getElementById('progress-wrap').classList.add('show'); document.getElementById('result-box').classList.remove('show'); const pdfSize = document.getElementById('pdf-size').value; const orient = document.getElementById('pdf-orient').value; const scale = parseFloat(document.getElementById('pdf-scale').value); const includeBg = document.getElementById('pdf-bg').value === 'yes'; try { setProgress(10, 'Preparando renderização...'); const container = document.createElement('div'); container.style.cssText = 'position:fixed;left:-9999px;top:0;width:900px;background:white;z-index:-1'; container.innerHTML = html; document.body.appendChild(container); setProgress(30, 'Renderizando HTML...'); await new Promise(r => setTimeout(r, 300)); const canvas = await html2canvas(container, { scale, useCORS: true, allowTaint: true, backgroundColor: includeBg ? null : '#ffffff', logging: false, windowWidth: 900, }); document.body.removeChild(container); setProgress(70, 'Gerando PDF...'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: orient, unit: 'pt', format: pdfSize, compress: true }); const docW = pdf.internal.pageSize.getWidth(); const docH = pdf.internal.pageSize.getHeight(); const imgW = docW; const imgH = (canvas.height * docW) / canvas.width; const imgData = canvas.toDataURL('image/jpeg', 0.92); let yOffset = 0; let pageNum = 0; while (yOffset < imgH) { if (pageNum > 0) pdf.addPage(pdfSize, orient); pdf.addImage(imgData, 'JPEG', 0, -yOffset, imgW, imgH, undefined, 'FAST'); yOffset += docH; pageNum++; } setProgress(95, 'Finalizando...'); const bytes = pdf.output('arraybuffer'); const blob = new Blob([bytes], { type: 'application/pdf' }); setProgress(100, 'Concluído!'); setTimeout(() => { const url = URL.createObjectURL(blob); document.getElementById('download-link').href = url; document.getElementById('result-sub').textContent = pageNum + ' página' + (pageNum > 1 ? 's' : '') + ' · ' + formatBytes(blob.size); document.getElementById('progress-wrap').classList.remove('show'); document.getElementById('result-box').classList.add('show'); document.getElementById('result-box').scrollIntoView({ behavior: 'smooth', block: 'center' }); btn.disabled = false; btn.textContent = '🌐 Converter novamente'; }, 400); } catch (err) { console.error(err); showToast('❌ Erro ao converter. Verifique se o HTML é válido.'); btn.disabled = false; btn.textContent = '🌐 Converter para PDF'; document.getElementById('progress-wrap').classList.remove('show'); } } // ─── Helpers ────────────────────────────────────────────────── function setProgress(pct, label) { document.getElementById('progress-bar').style.width = pct + '%'; document.getElementById('progress-pct').textContent = pct + '%'; document.getElementById('progress-text').textContent = label; } function softReset() { document.getElementById('result-box').classList.remove('show'); document.getElementById('progress-wrap').classList.remove('show'); document.getElementById('progress-bar').style.width = '0%'; } function formatBytes(b) { if (b < 1024) return b + ' B'; if (b < 1048576) return (b / 1024).toFixed(1) + ' KB'; return (b / 1048576).toFixed(2) + ' MB'; } function toggleFaq(btn) { const expanded = btn.getAttribute('aria-expanded') === 'true'; document.querySelectorAll('.faq-q').forEach(b => { b.setAttribute('aria-expanded', 'false'); b.nextElementSibling && b.nextElementSibling.classList.remove('open'); }); if (!expanded) { btn.setAttribute('aria-expanded', 'true'); btn.nextElementSibling && btn.nextElementSibling.classList.add('open'); } }