samt / barcode

barcode generation for nodejs
MIT License
69 stars 59 forks source link

Generated Barcode is not readable #10

Closed nilesh211 closed 9 years ago

nilesh211 commented 9 years ago

Hi, I followed the steps provided. I am able to generate the barcode. But the generated barcode value is not readable in barcode scanner. Can you please advise if i might have missed some steps.

samt commented 9 years ago

Can you attach an output image to this ticket and post a relevant code snippet?

nilesh211 commented 9 years ago
var PDFDocument = require('pdfkit');
var BarCode = require('barcode');
var doc = new PDFDocument({margin: 20});
doc.pipe(res);
doc.pipe(fileSystem.createWriteStream(fPdfName));

var barCodeText = '001,221,Nilesh';
var code39 = BarCode('code39', {
    data: barCodeText,
    width: 400,
    height: 100
});

code39.getBase64(function (err, imgsrc) {
    if (err) throw err;

    doc.moveDown(0.7)
    .image(imgsrc, {
        width: 220,
        height: 25,
        x: 363,
        y: 60
    })
});

image

nilesh211 commented 9 years ago

I had one more query.. Suppose i need to deploy my code to hereku server then how to install graphicsmagicx in it??? i have install graphicsmagick in my system and the barcode is generated.. ..what if i deploy it in hereku server??

samt commented 9 years ago

If Heroku does not have Graphics Magic installed, it cannot run, I am afraid.

nilesh211 commented 9 years ago

Thanks Sam... Can you please let me know why the barcode generated is not readable through barcode scanner?

samt commented 9 years ago

If you increase the pixel width of your output image, you should be able to read it with a scanner. What's going on here is that that the image is being squished which makes it hard for the scanner to distinguish between narrow bars and wide bars.

Additionally, code39 takes a lot of space to represent the data you give it, so it's really only good for short numbers or short phrases. If your barcode gets too long with code39, you might want to try a higher density barcode or shorten your message you're sending through.

samt commented 9 years ago

Making this easier to surface to the user, see #14