PDF/print tools + Kazakh i18n, pdfmake vector export

This commit is contained in:
renat_togussov 2026-10-15 12:37:06 +00:00
parent d81dcd59b2
commit d9fc110207

View File

@ -9,6 +9,9 @@
<link rel="stylesheet" href="design-system/kt-ai-tokens.css">
<link rel="stylesheet" href="design-system/kt-ai-components.css">
<link rel="stylesheet" href="design-system/kt-ai-page.css">
<link rel="stylesheet" href="design-system/kt-ai-print.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.10/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.10/vfs_fonts.js"></script>
<style>
a.kt-ai-btn { text-decoration: none; }
body { margin: 0; }
@ -138,6 +141,10 @@
border-radius: var(--kt-ai-radius-full);
padding: 3px;
}
.dl-btn {
display: none;
}
@media (min-width: 1024px) { .dl-btn { display: inline-flex; } }
.lang-btn {
border: none;
background: transparent;
@ -155,6 +162,29 @@
background: linear-gradient(90deg, var(--kt-blue-600), var(--kt-blue-500));
color: var(--kt-snow);
}
.print-tools {
display: flex;
gap: var(--kt-ai-space-3);
}
.hero-dl {
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
border-radius: var(--kt-ai-radius-full);
background: var(--kt-ai-fg-on-fill);
color: var(--kt-blue-600);
margin-left: var(--kt-ai-space-2);
text-decoration: none;
flex-shrink: 0;
}
.hero-dl:hover { opacity: .85; }
@media print {
.lang-switch, .brand-chip, .print-tools, .kt-ai-pagehead { display: none !important; }
.poster { min-height: auto; }
.poster-main { padding: 24px 0; }
}
</style>
</head>
<body class="poster">
@ -172,6 +202,14 @@
<button class="lang-btn active" data-lang="ru" type="button" aria-pressed="true">RU</button>
<button class="lang-btn" data-lang="kk" type="button" aria-pressed="false">ҚАЗ</button>
</div>
<div class="print-tools">
<button class="kt-ai-btn" data-size="sm" type="button" id="btn-print">
<svg class="kt-icon kt-icon-sm" aria-hidden="true"><use href="#download"></use></svg> Печать
</button>
<button class="kt-ai-btn" data-variant="primary" data-size="sm" type="button" id="btn-pdf">
<svg class="kt-icon kt-icon-sm" aria-hidden="true"><use href="#file"></use></svg> Векторный PDF
</button>
</div>
</div>
</header>
@ -181,6 +219,10 @@
<div class="kt-ai-chip hero-chip" style="margin-bottom:var(--kt-ai-space-5)">
<svg class="kt-icon" aria-hidden="true"><use href="#eye"></use></svg>
<span data-i18n="chip">Инструктаж перед каждым выездом</span>
<a class="hero-dl" id="hero-dl" href="plakat-360-ru.html" download
title="Скачать плакат (RU) для печати / PDF">
<svg class="kt-icon kt-icon-sm" aria-hidden="true"><use href="#download"></use></svg>
</a>
</div>
<h1 class="poster-title" data-i18n="title">Осмотр 360°</h1>
<p class="poster-sub" data-i18n-html="sub">
@ -309,6 +351,60 @@ var I18N = {
document.querySelectorAll(".lang-btn").forEach(function(b){
b.addEventListener("click", function(){ apply(b.getAttribute("data-lang")); });
});
function curLang(){
var a = document.querySelector(".lang-btn.active");
return a ? a.getAttribute("data-lang") : "ru";
}
function renderPdf(lang, filename){
if (typeof pdfMake === "undefined") { alert("PDF-движок ещё не загрузился — повторите через пару секунд, или используйте кнопку «Печать»."); return; }
var d = I18N[lang] || I18N.ru;
function tile(n, t, p, back){
return {
width:1, margin:10,
border: back ? {color:RED, width:2, style:"solid"} : null,
background: back ? "#fff5f5" : PAPER,
stack:[
{text:n, color:(back?RED:BLUE), fontSize:30, bold:true, alignment:"center", margin:[0,0,0,0]},
{text:t, color:INK, fontSize:21, bold:true, alignment:"center", margin:[0,8,0,8]},
{text:p, color:MUT, fontSize:12.5, alignment:"center", lineHeight:1.35}
]
};
}
var docDef = {
content:[
{text:d.chip, color:PAPER, fontSize:13, bold:true, alignment:"center",
backgroundColor:BLUE2, margin:[0,0,0,14]},
{text:d.title, color:BLUE, fontSize:56, bold:true, alignment:"center",
margin:[0,0,0,10]},
{text:d.sectionSub, color:MUT, fontSize:16, alignment:"center",
lineHeight:1.4, margin:[24,0,24,16]},
{columns:[
tile("01", d.side1, d.side1p, false),
tile("02", d.side2, d.side2p, false),
tile("03", d.side3, d.side3p, true),
tile("04", d.side4, d.side4p, false)
], margin:[16,0,16,16]},
{border:{color:RED, width:2, style:"solid"}, background:"#fff5f5",
margin:[16,0,16,16],
stack:[
{text:d.warn1, color:INK, fontSize:15, bold:true, lineHeight:1.35, margin:[0,0,0,4]},
{text:d.warn2, color:MUT, fontSize:12, lineHeight:1.3}
]},
{text:[
{text:d.slogan1+" — ", color:INK, bold:true},
{text:d.slogan2, color:BLUE, bold:true}
], fontSize:34, alignment:"center", margin:[0,20,0,0]}
]
};
pdfMake.createPdf(docDef).download(filename);
}
function doPdf(){
var l = curLang();
var name = l==="kk" ? "plakat-360-kk.pdf" : "plakat-360-ru.pdf";
renderPdf(l, name);
}
document.getElementById("btn-print").addEventListener("click", function(){ window.print(); });
document.getElementById("btn-pdf").addEventListener("click", doPdf);
apply(saved);
})();
</script>