Skip to content

Commit

Permalink
qrcode print v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Andersson committed May 16, 2024
1 parent 436de36 commit 3a23120
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/labels/advertLabelModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,31 @@ export const advertLabelModule =
ctx.response.type = 'application/pdf'
ctx.res.setHeader(
'Content-disposition',
'inline; filename="labels.pdf"'
'inline; filename="etiketter.pdf"'
)
ctx.status = 200

const labelSize = 144 // 72 points/inch
const margin = labelSize / 12
const rowHeight = labelSize / 6
const codeGap = 3
const codeHeight = rowHeight * 4 - codeGap
const codeCenter = labelSize / 2 - codeHeight / 2

// Text Positioning
const textOptions: PDFKit.Mixins.TextOptions = {
align: 'center',
width: Math.max(labelSize - margin * 2, 0),
height: Math.max(rowHeight - margin, 0),
lineBreak: false,
}
// Create document
const doc = new PDFDocument({
size: [250, 250],
size: [labelSize, labelSize],
autoFirstPage: false,
margin,
})
doc.fontSize(18)
doc.fontSize(textOptions.height ?? 0)
doc.pipe(ctx.res)

await Promise.all(
Expand All @@ -67,26 +83,21 @@ export const advertLabelModule =
)}`,
{
margin: 0,
width: 170,
width: codeHeight * 2,
}
).then(qr => {
doc
.addPage()
.text(labelOptions.headline, 10, 25, {
align: 'center',
height: 0,
width: 230,
lineBreak: false,
})
.image(qr, 40, 45, {
width: 170,
})
.text(createLabelFooter(labelOptions, advert), 10, 220, {
align: 'center',
width: 230,
height: 0,
lineBreak: false,
.text(labelOptions.headline, margin, margin, textOptions)
.image(qr, codeCenter, rowHeight, {
cover: [codeHeight, codeHeight],
})
.text(
createLabelFooter(labelOptions, advert),
margin,
5 * rowHeight,
textOptions
)
})
)
)
Expand Down

0 comments on commit 3a23120

Please sign in to comment.