1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
function pdfHLExp (title, highlight) {
const theme = []
const content = []
const backColor =
{ multi: '#E3F2F5', p1: '#FEF2E4', p2: '#FEF2CE', p3: '#FEFAE7', adt: '#FFF5F2', pat: '#FFF2F6', pcut: '#E3F2F5', hdm: '#E6F0F8', gts: '#E6E7F8', asep: '#EEE6F8' }
const couleur = { gray: '#888888', warning: '#F7A438', danger: '#F9434F', success: '#71CE3C' }
for (let h in highlight) {
const clas = highlight[h].class
const col = []
const tab = [{ columns: col }]
theme.push({ text: highlight[h].title, fontSize: 16, margin: [0, 25, 0, 0], background: backColor[clas], alignment: 'center' })
for (let v in highlight[h].values) {
let hv = highlight[h].values[v].v
let tv = highlight[h].values[v].t
let regBr = /<br>/gi
let tvnobr = tv.replace(regBr, ' ')
const svg = `
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<g>
<ellipse ry="50" rx="50" id="svg_1" cy="50" cx="50" stroke-width="0" stroke="#000" fill= "${couleur[highlight[h].values[v].c]}"/>
<text xml:space="preserve" text-anchor="start" font-family="Lato" font-size="24" id="svg_2" y="31.5" x="22.5" stroke-width="0" stroke="#000" fill="#FFFFFF">${hv}%</text>
<text xml:space="preserve" text-anchor="start" font-family="Lato" font-size="16" id="svg_3" y="55.5" x="9.5" stroke-width="0" stroke="#000" fill="#FFFFF">"${tvnobr}"</text>
</g>
</svg>`
col.push({ svg: svg, margin: [0, 10, 0, 0], alignment: 'center' })
}
theme.push(tab)
}
content.push(theme)
const definition = {
pageStyle: 'A4',
content: content,
footer: (current, count) => {
return {
text: `${title} - page ${current}/${count}`,
fontSize: 6,
alignment: 'center'
}
}
}
const filename = `${title}.pdf`
pdf.createPdf(definition).download(filename)
} |
Partager