Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var readline = require('readline');
- var rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout,
- terminal: false
- });
- var starting;
- var ending;
- rl.question('Enter starting value: ', function(startingValue) {
- // Prompt user for inputting starting value
- starting = startingValue;
- rl.question('Enter ending value: ', function(endingValue) {
- // Prompt user for inputting ending value
- ending = endingValue;
- console.log('starting:' + starting + ', ending:' + ending);
- generateBarcode(starting);
- rl.close();
- process.stdin.destroy();
- });
- });
- function generateBarcode(toPrint) {
- // Method to generate barcode
- console.log(toPrint);
- var bwipjs = require('bwip-js');
- var fs = require('fs');
- // Optionally load some custom fonts. Maximum 8.
- // OpenType and TrueType are supported.
- bwipjs.loadFont('Inconsolata', 108,
- require('fs').readFileSync('fonts/Inconsolata.otf', 'binary'));
- bwipjs.toBuffer({
- bcid: 'code128', // Barcode type
- text: toPrint, // Text to encode
- scale: 3, // 3x scaling factor
- height: 10, // Bar height, in millimeters
- includetext: true, // Show human-readable text
- textxalign: 'center', // Always good to set this
- textfont: 'Inconsolata', // Use your custom font
- textsize: 13 // Font size, in points
- }, function(err, png) {
- if (err) {
- // Decide how to handle the error
- // `err` may be a string or Error object
- } else {
- // Write the barcode as image file and save it
- fs.writeFile(__dirname + '/' + toPrint + '.png', png, function() {
- console.log('Generated Barcode');
- toPrint++;
- if (toPrint < ending) {
- generateBarcode(toPrint);
- }
- });
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement