Bar Width Adjustment (BWR) for barcodes

Help
2013-06-05
2013-09-20
  • Robert Stott

    Robert Stott - 2013-06-05

    Hi,

    Is it possible to adjust the width of the bars in a bar code? This is sometimes required to compensate for ink spreading slightly when it's applied to the paper in printing.

    Any ideas or suggestions would be appreciated!

    Thanks
    Rob

     
  • Robert Stott

    Robert Stott - 2013-06-13

    No ideas? :-(

     
  • James Holland

    James Holland - 2013-06-19

    Hi Robert,

    This isn't something TCPDF currently supports AFAIK.

    I print barcodes using a laser printer and a Datamax label printer and haven't had any readability issues (although I do keep to a decent size for the barcodes).

    Have you had issues with this? If so what type of printer are you printing to? If you are sending artwork to a professional printer, they usually remove your barcode and place in their own anyway as each printer's parameters will be slightly different.

    Thanks

    James

     
  • Robert Stott

    Robert Stott - 2013-06-20

    Hi James,

    I just realised that I'd requested this feature a few years ago with no luck.

    I work for one of those professional printers and that's why we need it. ;-) Basically, when you apply ink on press you have to account for the 'spread' of the ink by reducing the width of the bars by the corresponding amount.

    It's really annoying because its just the lack of this bar width reduction that's stopping us using tcpdf.

    For anyone whose interested...

    http://www.barcode-test.com/barcode-tutorial/bar-width-reduction-2

    Regards
    Rob

     
    Last edit: Robert Stott 2013-06-21
  • James Holland

    James Holland - 2013-07-23

    Hi Rob,

    I had a quick look at the code for barcodes and I think I can see a way to work in BWR, but I'm not sure how would be best to implement given that the bars can be different widths and I don't work with this kind of thing.

    Would a percentage work?

    E.g. $style['bwg']=10; would reduce the width of the printed bars by 10% etc.
    Or should it be a specific figure e.g. $style['bwg']=0.02; would reduce the width of the printed bars by 0.02 user units (usually mm).

    What are your thoughts?

     
  • James Holland

    James Holland - 2013-07-24

    Having slept on it, it must be a fixed mm reduction as the ink will spread by a fixed amount.

    In the tcpdf.php file on line 15286 change:

    $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);

    To:

    $this->Rect($xpos, $ypos + ($style['bwr'] / 2), $bw - ($style['bwr'] / 2), ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);

    Then when you are constructing your barcode specify the BWR using $style['bwr']=0.2; (This will reduce the width by 0.2mm

    If you have any problems, let me know, if you are happy with it, I will contact Nicola and ask if it is something that could be added to the source - although I'd have to add a bit of validation to make sure the reduction isn't more than the actual with of the bars first.

    Thanks

    James

     
    Last edit: James Holland 2013-07-24
  • Robert Stott

    Robert Stott - 2013-07-26

    Oooh! That's very interesting. I'll have a look at that one and get back to you. Thanks.

     
  • Greg57

    Greg57 - 2013-07-27

    Seems to be the solution of my problem (topic : Barcode C128 - Black bar size vs white size).
    I will check that on monday.

    Thanks !

    Greg

     
  • Robert Stott

    Robert Stott - 2013-07-31

    Hmm. Seems we're some of the way there, but not quite. The bar widths are reduced, but not by the amount I'd expect. If a barcode had a BWR of 0.01mm then I'd expect its overall width to be 0.01mm less than if it had no BWR applied.

    I've attached PDFs showing barcodes with and without BWR. "bwr example.pdf" shows barcodes from our existing solution. "from tcpdf.pdf" shows the codes produced by tcpdf. I've also included my PHP just in case I've done something dumb (quite likely!).

    Hope that's some help. Let me know if there's anything I can do to help.

    Rob

     
  • James Holland

    James Holland - 2013-07-31

    Hi Rob,

    I have opened the examples using Photoshop and Illustrator, and the example files have no discerning difference (I guess that's almost the point) - but could you send me an exaggerated example please e.g. reduce by 2mm if that is possible so I can see the difference.

    I'd assumed that the way it works is to reduce each bar individually i.e. if your ink spreads by 0.01mm then a single bar that would want to be 1mm should be created as 0.99mm and a double bar that should be 2mm would be created as 1.99mm etc. By implication a gap that should be 1mm would become 1.01mm to account for the spread of the ink.

    I guess that this isn't how it works?

    Send me a grossly exaggerated example - one where you can see the difference by eye - and I'll re-look at it.

    Thanks

    James

     
  • Robert Stott

    Robert Stott - 2013-07-31

    Yeah, I think you understand it correctly. I'll try to get you a better example.

     
  • Robert Stott

    Robert Stott - 2013-08-29

    Hi,

    Apologies for taking a little while to get back.

    I've included an example of two barcodes, the top has no bar but the second has 0.01mm bwr applied. I've also magnified it 400% and overlaid them so hopefully that'll show things a little clearer.

    If you look at the first bar with no BWR then it's 0.4mm wide. That means that the code with 0.01mm bwr applied should be 0.39mm wide, but it's not, it's 0.35mm wide.

    Also, the centre line of each bar should remain the same between the code with BWR applied and without bwr applied.

    We're so close here! It'd be great if you could have another look.

    Thanks
    Rob

     
  • Nicola Asuni

    Nicola Asuni - 2013-08-29

    If you are using the latest TCPDF version, then you can set the following parameter on write1DBarcode method:

    $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm)

     
  • James Holland

    James Holland - 2013-08-29

    Robert, my bad, I hadn't tested the code properly. Try:

    $this->Rect($xpos + ($style['bwr'] / 2), $ypos, $bw - $style['bwr'], ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);

    As a replacement to the above line.

    This moves the starting point of the bar over by half of the bwr and reduces the width of the bar by the bwr.

    Nicola, BWR reduces the width of printed bars only to compensate for ink spread so instead of 0.4mm bar, 0.4mm gap, 0.4mm bar we have 0.39mm bar, 0.42mm gap, 0.39mm bar. Similarly a double bar would be 0.79mm from 0.8mm as the spread would still be only 0.01mm. Once printed the ink spreads and the end result is a perfect scanning 0.4mm barcode!

    Thanks

    James

     
  • Robert Stott

    Robert Stott - 2013-09-17

    Ah! That sounds promising. I'll give it a test when I have a few mins to spare - things are pretty hectic at the moment! Thanks very much for your help so far.

     
  • Robert Stott

    Robert Stott - 2013-09-20

    I did some very quick testing and that's looking pretty good to me. I'll generate some barcodes using our existing solution, compare results and get back to you. So far so good. Thanks so much for your help!

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks