Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. var readline = require('readline');
  2. var rl = readline.createInterface({
  3. input: process.stdin,
  4. output: process.stdout,
  5. terminal: false
  6. });
  7.  
  8. var starting;
  9. var ending;
  10. rl.question('Enter starting value: ', function(startingValue) {
  11. // Prompt user for inputting starting value
  12. starting = startingValue;
  13. rl.question('Enter ending value: ', function(endingValue) {
  14. // Prompt user for inputting ending value
  15. ending = endingValue;
  16. console.log('starting:' + starting + ', ending:' + ending);
  17. generateBarcode(starting);
  18.  
  19. rl.close();
  20. process.stdin.destroy();
  21. });
  22.  
  23. });
  24.  
  25. function generateBarcode(toPrint) {
  26. // Method to generate barcode
  27. console.log(toPrint);
  28. var bwipjs = require('bwip-js');
  29. var fs = require('fs');
  30. // Optionally load some custom fonts. Maximum 8.
  31. // OpenType and TrueType are supported.
  32. bwipjs.loadFont('Inconsolata', 108,
  33. require('fs').readFileSync('fonts/Inconsolata.otf', 'binary'));
  34.  
  35. bwipjs.toBuffer({
  36. bcid: 'code128', // Barcode type
  37. text: toPrint, // Text to encode
  38. scale: 3, // 3x scaling factor
  39. height: 10, // Bar height, in millimeters
  40. includetext: true, // Show human-readable text
  41. textxalign: 'center', // Always good to set this
  42. textfont: 'Inconsolata', // Use your custom font
  43. textsize: 13 // Font size, in points
  44. }, function(err, png) {
  45. if (err) {
  46. // Decide how to handle the error
  47. // `err` may be a string or Error object
  48. } else {
  49. // Write the barcode as image file and save it
  50. fs.writeFile(__dirname + '/' + toPrint + '.png', png, function() {
  51. console.log('Generated Barcode');
  52.  
  53. toPrint++;
  54. if (toPrint < ending) {
  55. generateBarcode(toPrint);
  56. }
  57. });
  58. }
  59. });
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement