Added barcode generatin

ref #19
This commit is contained in:
Nicolai Ort 2021-02-09 19:15:08 +01:00
parent b77945a9e4
commit 5c075bce8b
3 changed files with 14 additions and 7 deletions

View File

@ -123,7 +123,7 @@ export class PdfCreator {
* @param cards The runner cars you want to generate the cards for.
* @param locale The locale used for the cards (default:en)
*/
public async generateRunnerCards(cards: RunnerCard[], locale: string = "en"): Promise<Buffer> {
public async generateRunnerCards(cards: RunnerCard[], locale: string = "en", codeformat: string = config.codeformat): Promise<Buffer> {
if (cards.length > 10) {
let pdf_promises = new Array<Promise<Buffer>>();
let i, j;
@ -138,7 +138,8 @@ export class PdfCreator {
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, cards_swapped, eventname: "LfK! 2069" })
let result = template({ cards, cards_swapped, eventname: "LfK! 2069", codeformat: "qrcode" })
result = await awaitAsyncHandlebarHelpers(result);
const pdf = await this.renderPdf(result, { format: "A4", landscape: false });
return pdf
}

View File

@ -3,6 +3,7 @@ import bwipjs from "bwip-js";
export const asyncHelpers = new AsyncHelpers();
async function generateBarcode(str, options, emtpy, cb) {
if (str == null) { cb(null, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg=="); return; }
let res = await generateBase64Barcode(options.toString(), str.toString());
cb(null, res);
}
@ -18,7 +19,7 @@ export async function generateBase64Barcode(type: string, content: string): Prom
height: 10,
width: 10,
includetext: true,
textxalign: 'center',
textxalign: 'center'
}
if (type != "qrcode") {
delete options.width;

View File

@ -38,15 +38,17 @@
<div class="columns" style="height: 6rem; overflow: hidden;">
<div class="column is-two-thirds">
<!--SPONSOR LOGO HERE-->
<img src="https://odit.services/assets/img/profile-pic-no_bg.hash.0c81702a.png" width="60%" />
<img style="vertical-align: revert; margin-top: auto; object-fit: cover; max-height: 2cm;"
src="https://odit.services/assets/img/profile-pic-no_bg.hash.0c81702a.png" />
</div>
<div class="column is-one-third">
<!--BARCODE HERE-->
<img src="https://odit.services/assets/img/profile-pic-no_bg.hash.0c81702a.png" width="100%" />
<img style="vertical-align: revert; margin-top: auto; object-fit: cover; max-height: 2cm;"
src="{{--bc this.id ../codeformat}}" />
</div>
</div>
<p>{{this.runner.lastname}}, {{this.runner.firstname}} {{this.runner.middlename}}</p>
<p>{{this.runner.group.name}} {{this.id}}</p>
<p>{{this.runner.group.name}}</p>
</div>
{{/each}}
</div>
@ -55,9 +57,12 @@
<div class="columns is-multiline">
{{#each cards_swapped}}
<div class="column is-half runnercard">
<p>{{this.id}}</p>
<!--SPONSOR LOGO FIRST-->
<img style="vertical-align: revert; margin-top: auto; object-fit: cover; max-height: 2cm;"
src="https://odit.services/assets/img/profile-pic-no_bg.hash.0c81702a.png" />
<!--BARCODE SECOND-->
<img style="vertical-align: revert; margin-top: auto; object-fit: cover; max-height: 2cm;"
src="{{--bc this.id ../codeformat}}" />
</div>
{{/each}}
</div>