Library
sh
npm install barcode-graderjs
import { gradeFile, formatReport } from "barcode-grader";
const report = await gradeFile("label.pdf", { pages: [1], process: "flexo" });
for (const code of report.codes) {
console.log(code.name, code.value, code.verdict, code.size?.magnification, code.grade?.letter);
for (const issue of code.issues) console.log(` ${issue.rule}: ${issue.text}`);
}
console.log(formatReport(report, "label.pdf"));gradeFile takes a path or the file's bytes.
Options
| option | meaning |
|---|---|
pages | page numbers of a PDF to read |
widthMm | a picture's printed width in mm, when the file has no resolution |
dpi | a picture's resolution, overriding the file's |
process | "flexo", "offset", "gravure" or "digital" |
hri | compare the digits printed under EAN/UPC codes with what they encode (default true) |
What a code carries
| field | content |
|---|---|
name, format, value, text | what it is and what it says |
page, box | where it is; box is fractions of the page |
verdict | "ok", "check" or "fail" |
issues | each with its rule, level and text |
checkDigit | whether it is right, and what it should be |
size | X-dimension in mm, magnification, and GS1's range for the application |
barHeight | measured, and needed at this size |
quiet | clear space each side in modules, and what the symbology needs |
colour | bar and space colours, symbol contrast in red light |
grade | letter, value, the 2.8/06/660 notation, and the parameter that limited it |
summary | one paragraph in plain words |
Types ship with the package. The JSON form of a report is described by barcode-grader/schema/report.schema.json.
Judging alone
barcode-grader/rules exports gradeCodes, for callers with their own renderer and decoder.