feat: add script to export training slides to PDF in 16:9 format
This commit is contained in:
1 parent
d530356101
commit
f93e0fe460
31 files changed
+54144
-487
No files matched your search
@@ -1965,108 +1965,7 @@ Temperatura: 26.1 C | Umidade: 62.0 %</code></pre>
|
||||
window.PagedConfig = {
|
||||
before: () => document.querySelector(".aviso-carregando")?.remove(),
|
||||
};
|
||||
|
||||
function montarPainelFlutuante() {
|
||||
if (document.getElementById("painelExportacao")) return;
|
||||
|
||||
// Injeta estilo para position fixed sem ser sanitizado pelo parser do Paged.js
|
||||
const style = document.createElement("style");
|
||||
style.textContent = `
|
||||
#painelExportacao {
|
||||
position: fixed !important;
|
||||
top: 18px !important;
|
||||
right: 20px !important;
|
||||
z-index: 999999 !important;
|
||||
display: flex !important;
|
||||
}
|
||||
#toastExportacao {
|
||||
position: fixed !important;
|
||||
bottom: 24px !important;
|
||||
right: 24px !important;
|
||||
z-index: 1000000 !important;
|
||||
}
|
||||
@media print {
|
||||
#painelExportacao, #toastExportacao {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(style);
|
||||
|
||||
const painel = document.createElement("div");
|
||||
painel.id = "painelExportacao";
|
||||
painel.className = "painel-exportacao";
|
||||
painel.innerHTML = `
|
||||
<span class="painel-exportacao-titulo">
|
||||
<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 6 2 18 2 18 9"></polyline><path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"></path><rect x="6" y="14" width="12" height="8"></rect></svg>
|
||||
Apostila:
|
||||
</span>
|
||||
<button type="button" class="btn-exportar btn-exportar-rgb" id="btnExportarRgb" title="Imprimir ou Salvar em PDF (padrão RGB)">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>
|
||||
<span>Exportar PDF</span>
|
||||
</button>
|
||||
<button type="button" class="btn-exportar btn-exportar-cmyk" id="btnExportarCmyk" title="Exportar PDF em CMYK (ISO Coated) para gráfica">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"></path><path d="M2 12h20"></path></svg>
|
||||
<span>Exportar em CMYK</span>
|
||||
</button>
|
||||
`;
|
||||
|
||||
const toast = document.createElement("div");
|
||||
toast.id = "toastExportacao";
|
||||
toast.className = "toast-exportacao";
|
||||
|
||||
document.body.appendChild(painel);
|
||||
document.body.appendChild(toast);
|
||||
|
||||
document.getElementById("btnExportarRgb").onclick = () => window.print();
|
||||
|
||||
document.getElementById("btnExportarCmyk").onclick = async () => {
|
||||
const btn = document.getElementById("btnExportarCmyk");
|
||||
const txt = btn.innerHTML;
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = `<span class="spinner-exportar"></span><span>Baixando CMYK...</span>`;
|
||||
exibirToast("Gerando PDF em CMYK (ISO Coated)... O download iniciará em instantes.", "info", 15000);
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/export-cmyk?modulo=1");
|
||||
if (!res.ok) throw new Error("Erro no servidor (" + res.status + ")");
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.style.display = "none";
|
||||
a.href = url;
|
||||
a.download = "LASER-ESP32-Modulo-1-CMYK.pdf";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(() => { a.remove(); URL.revokeObjectURL(url); }, 1000);
|
||||
exibirToast("✅ PDF em CMYK baixado com sucesso!", "sucesso", 4000);
|
||||
} catch (err) {
|
||||
console.error("Erro CMYK:", err);
|
||||
exibirToast("❌ Erro ao baixar PDF: " + err.message, "erro", 6000);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = txt;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function exibirToast(msg, tipo = "info", dur = 4000) {
|
||||
const t = document.getElementById("toastExportacao");
|
||||
if (!t) return;
|
||||
t.textContent = msg;
|
||||
t.className = "toast-exportacao ativo " + tipo;
|
||||
clearTimeout(t._timer);
|
||||
t._timer = setTimeout(() => t.classList.remove("ativo"), dur);
|
||||
}
|
||||
</script>
|
||||
<script src="../assets/paged.polyfill.js"></script>
|
||||
<script>
|
||||
class ExportHandler extends window.Paged.Handler {
|
||||
afterRendered() {
|
||||
montarPainelFlutuante();
|
||||
}
|
||||
}
|
||||
window.Paged.registerHandlers(ExportHandler);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user