Skip to content
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
8 changes: 6 additions & 2 deletions .env_example
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ BARCODE_MINCODELENGTH=3
# 💾 Show backup button in the top navigation bar (1 = show, 0 = hide)
ADMIN_BUTTON_SWITCH=1


#############################################
# 🏫 BUSINESS CONFIGURATION
#############################################
Expand Down Expand Up @@ -152,4 +151,9 @@ USERLABEL_LINE_3=["User.schoolGrade","90%","3%","35vw","2pt","black",12]

# 🔲 Barcode for user labels
# Format: [top, left, width, height, version]
USERLABEL_BARCODE=["80%","63%","3cm","1.6cm","code128"]
USERLABEL_BARCODE=["80%","63%","3cm","1.6cm","code128"]

# Prefix und Suffix für den Barcode.
# Beispiele: Escape: \x1B | Enter: \x0D | Tabulator: \x09 | Backspace: \x08 | Line Feed: \x0A | Home (Pos 1): \x01
USERLABEL_BARCODE_PREFIX="" # Optionales Steuerzeichen vor Eingabe der Ausweisnummer (z.B. ESC)
USERLABEL_BARCODE_SUFFIX="" # Suffix für den Barcode (z.B. um mit einem Zeilenumbruch zu enden)
20 changes: 17 additions & 3 deletions pages/api/report/userlabels/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ const barcodeMinLength: number =
? parseInt(process.env.BARCODE_MINCODELENGTH)
: DEFAULT_BARCODE_MINCODELENGTH;

// Postfix & Prefix for Barcode
// Hilfs-Funktion zum "Auflösen" von Hex-Strings aus Barcode Prefix/Suffix
const parseEnv = (str: string) =>
str.replace(/\\x([0-9A-Fa-f]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
.replace(/\\r/g, "\r")
.replace(/\\n/g, "\n")
.replace(/\\t/g, "\t");

const barcodePrefix = parseEnv(process.env.USERLABEL_BARCODE_PREFIX || "");
const barcodeSuffix = parseEnv(process.env.USERLABEL_BARCODE_SUFFIX || "");


// =============================================================================
// Styles
// =============================================================================
Expand Down Expand Up @@ -221,13 +233,15 @@ const generateBarcode = async (id: string) => {

try {
const png = await bwipjs.toBuffer({
bcid: BARCODE_SETTINGS[4], // Barcode type (e.g., 'code128')
text: barId,
bcid: BARCODE_SETTINGS[4],
text: barcodePrefix + barId + barcodeSuffix,
alttext: barId, // Zeigt unten nur die Nummer an
scale: 3,
parse: true,
height: 10,
includetext: true,
textxalign: "center",
});
});

return (
<PdfImage
Expand Down