@@ -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)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user