Fixed double-sided printing

ref #14
This commit is contained in:
Nicolai Ort 2021-02-08 16:14:10 +01:00
parent 68f46a45b5
commit 7f58dd694b
2 changed files with 23 additions and 5 deletions

View File

@ -129,10 +129,11 @@ export class PdfCreator {
const pdfs = await Promise.all(pdf_promises);
return await this.mergePdfs(pdfs);
}
const cards_swapped = this.swapArrayPairs(cards);
await i18next.changeLanguage(locale);
const template_source = fs.readFileSync(`${this.templateDir}/runner_card.html`, 'utf8');
const template = Handlebars.compile(template_source);
const result = template({ cards, eventname: "LfK! 2069" })
const result = template({ cards, cards_swapped, eventname: "LfK! 2069" })
const pdf = await this.renderPdf(result, { format: "A4", landscape: false });
return pdf
}
@ -220,4 +221,22 @@ export class PdfCreator {
runner.group = group;
return runner;
}
/**
* Swaps pairs (0/1, 2/3, ...) of elements in an array recursively.
* If the last element has no partner it inserts an empty element at the end and swaps the two
* This is needed to generate pdfs with front- and backside that get printet on one paper.
* @param array The array which's pairs shall get switched.
* @returns Array with swapped pairs,
*/
private swapArrayPairs(array): Array<any> {
if (array.length == 1) {
return [null, array[0]];
}
if (array.length == 0) {
return null;
}
return [array[1], array[0]].concat(this.swapArrayPairs(array.slice(2)));
}
}

View File

@ -46,19 +46,18 @@
</div>
</div>
<p>{{this.runner.lastname}}, {{this.runner.firstname}} {{this.runner.middlename}}</p>
<p>{{this.runner.group.name}}</p>
<p>{{this.runner.group.name}} {{this.id}}</p>
</div>
{{/each}}
</div>
</div>
<div class="sheet">
<div class="columns is-multiline">
{{#each cards}}
{{#each cards_swapped}}
<div class="column is-half runnercard">
<p>{{this.id}}</p>
<!--SPONSOR LOGO FIRST-->
<img src="https://odit.services/assets/img/profile-pic-no_bg.hash.0c81702a.png" height="2cm" />
<!--BARCODE SECOND-->
<img src="https://odit.services/assets/img/profile-pic-no_bg.hash.0c81702a.png" height="3.5cm" />
</div>
{{/each}}
</div>