Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QR code optionnel #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
"strategy": "default",
"clearDist": false,
"templatedURLs": {
"./": ["index.html"]
} }
"./": [
"index.html"
]
}
}
}
47 changes: 27 additions & 20 deletions src/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ function saveProfile () {
var dateSortie = field.value.split('-')
localStorage.setItem(field.id.substring('field-'.length), `${dateSortie[2]}/${dateSortie[1]}/${dateSortie[0]}`)
} else {
localStorage.setItem(field.id.substring('field-'.length), field.value)
if (field.id === "checkbox-qr") {
localStorage.setItem("generateQR", field.checked)
} else {
localStorage.setItem(field.id.substring('field-'.length), field.value)
}
}
}
}
Expand Down Expand Up @@ -158,29 +162,32 @@ async function generatePdf (profile, reasons) {
drawText(releaseMinutes, 220, 201)
}

// Date création
drawText('Date de création:', 464, 150, 7)
drawText(`${creationDate} à ${creationHour}`, 455, 144, 7)
// Générer un QR code si la case est cochée
if (profile.generateQR == "true") { // localStorage don't store boolean but string
// Date création
drawText('Date de création:', 464, 150, 7)
drawText(`${creationDate} à ${creationHour}`, 455, 144, 7)

const generatedQR = await generateQR(data)
const generatedQR = await generateQR(data)

const qrImage = await pdfDoc.embedPng(generatedQR)
const qrImage = await pdfDoc.embedPng(generatedQR)

page1.drawImage(qrImage, {
x: page1.getWidth() - 170,
y: 155,
width: 100,
height: 100,
})
page1.drawImage(qrImage, {
x: page1.getWidth() - 170,
y: 155,
width: 100,
height: 100,
})

pdfDoc.addPage()
const page2 = pdfDoc.getPages()[1]
page2.drawImage(qrImage, {
x: 50,
y: page2.getHeight() - 350,
width: 300,
height: 300,
})
pdfDoc.addPage()
const page2 = pdfDoc.getPages()[1]
page2.drawImage(qrImage, {
x: 50,
y: page2.getHeight() - 350,
width: 300,
height: 300,
})
}

const pdfBytes = await pdfDoc.save()

Expand Down
8 changes: 6 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ <h2 class="titre-2">Remplissez en ligne votre attestation numérique :</h2>
<span class="validity" aria-hidden="true"></span>
</div>
</div>



<div class="form-group">
<input class="form-check-input" type="checkbox" name="generate-qr" id="checkbox-qr" checked="checked">
<label class="form-check-label" for="checkbox-qr">Générer un QR code ?</label>
</div>

<p class="text-center mt-5">
<button type="button" id="generate-btn" class="btn btn-primary btn-attestation"><span ><i class="fa fa-file-pdf inline-block mr-1"></i> Générer mon attestation</span></button>
</p>
Expand Down