Skip to content

Michael Heydasch's picture

Printing Barcodes to an RTC Report

ArcherPoint How-To Blog: Step-by-step instructions on how to perform specific tasks in Microsoft Dynamics NAV

I was recently challenged to print a barcode on an RTC report. In the past, I have found barcode fonts rendered perfectly on NAV Classic reports. Those same barcode fonts would not render on the RTC report I was creating.

After trying several different barcode fonts with no success, I began to research online.   I found several posts discussing an inability to embed fonts. (Whether this is due to Reporting Services or RDLC is unclear to me.)

In my online searches, I also found freeware code submitted to Mibuso by Stijn Bossuyt labeled “EAN 8/13 Code 39/128 Barcode Creator v1.5”. (On the download page, credit is shared with Igor Pchelnikov, who submitted “Interleaved 2 of 5 Barcode Creator”.)

This utility works by encoding the barcode value, generating a barcode image in BMP format, and storing the image in a temporary record using table TempBlob.   While four objects are in the FOB and the TXT export file, only one of them – the codeunit – is required to be in a licensed range and may have to be renumbered.

The barcode is generated by a simple function call:  BarcodeMgt.EncodeCode128('*' + "Warehouse Location" + '*',2,FALSE,tempBlob2);  The first parameter is the text to encode, the second parameter is the size (1-5), the third parameter is whether the barcode should be generated as vertical, and the fourth parameter is a reference to the temporary record where the barcode image should be stored.

Proceeding further in my testing, I added a PictureBox to the Classic layout and changed the following properties:

  • SourceExpr, tempBlob.Blob
  • DataSetFieldName, BarcodePic

In Visual Studio, I dragged an Image control from the Toolbox to the layout and changed the following properties:

  • MIMEType, image/bmp
  • Source, Database
  • Value, =Fields!BarcodePic.Value

To my utter surprise, this worked on the first try. So I downloaded an app entitled “Barcode Scanner” to my Android smartphone and tested the barcode image with the app. Again, to my surprise and satisfaction, the barcode registered successfully within a fraction of a second.

I discovered one caveat … creating the barcode image seems to require a tremendous surge in CPU usage.   I found this out by accident when a couple dozen records or more matched the report filter and the report took a minute or so to render before appearing.   (During that delay, the CPU maxed out.)   So long as only one or a few barcodes are rendered in a single report run, the delay in report rendering is entirely acceptable.

sample barcodeThis alternative to barcode fonts for the purpose of barcode printing in the RTC was a nice piece of freeware.   Thanks and kudos to the creators.

If you enjoyed this blog, you might like to check out our collection of Development Blogs, as well as our "How To" blogs for practical advice on using Microsoft Dynamics NAV.

Blog Tags: 

Comments

Comment: 

I came around the samy problems you're facing, and there are some points to notice here:
1. I think it was clausl or henrik (i'am not sure) who said that custom fonts are available to rdlc reports but you need to restart te whole machine after installing the font to get it to work! So you should be able to achieve it this way.
2. As i found this out after rewriting the solution to the one you found too (Image creating by Stijn Bossuyt's Codeunit) i was faced the performance issues too, while inspecting the code i saw that every bit was written by its own, if you create a buffer mechanism (i simply used a 1024 Text var) to cache the bit stream you create, then the performance is significantly better!
Here is my CreateBarcodeDetail Function:
 

IF pblnVertical THEN BEGIN
  FOR lintBarLoop := 1 TO (bxtBarcodeBinary.LENGTH) DO BEGIN

    FOR lintLineLoop := 1 TO (pintLines * pintSize) DO BEGIN
      bxtBarcodeBinary.GETSUBTEXT(ltxtByte,lintBarLoop,1);

      IF ltxtByte = '1' THEN
        lchar := 0
      ELSE
        lchar := 255;

      poutBmpHeader.WRITE(lchar,1);
      poutBmpHeader.WRITE(lchar,1);
      poutBmpHeader.WRITE(lchar,1);
    END;

    FOR lintChainFiller := 1 TO (lintLineLoop MOD 4) DO BEGIN
      //Adding 0 bytes if needed - line end
      lchar := 0;
      poutBmpHeader.WRITE(lchar,1);
    END;
  END;
END ELSE BEGIN
  // For Better Performance, write a String for one line!
  BinaryStringLen := bxtBarcodeBinary.LENGTH;
  IF BinaryStringLen <= MAXSTRLEN(BinaryString) THEN BEGIN
    FOR lintBarLoop := 1 TO bxtBarcodeBinary.LENGTH DO BEGIN
      bxtBarcodeBinary.GETSUBTEXT(ltxtByte,lintBarLoop,1);

      IF ltxtByte = '1' THEN
        lchar := 0
      ELSE
        lchar := 255;

      FOR lintSize := 1 TO pintSize DO BEGIN
        //Putting Pixel: Black or White
        BinaryString += FORMAT(lchar);
        BinaryString += FORMAT(lchar);
        BinaryString += FORMAT(lchar);
      END
    END;

    FOR lintChainFiller := 1 TO ((lintBarLoop* pintSize) MOD 4) DO BEGIN
      //Adding 0 bytes if needed - line end
      lchar := 0;
      BinaryString += FORMAT(lchar);
    END;

    FOR lintLineLoop := 1 TO pintLines * pintSize DO BEGIN
      poutBmpHeader.WRITETEXT(BinaryString);
    END;
  END ELSE BEGIN // Slow Variant but allowes more than 1024 Bites per Line
    FOR lintLineLoop := 1 TO pintLines * pintSize DO BEGIN
      FOR lintBarLoop := 1 TO bxtBarcodeBinary.LENGTH DO BEGIN
        bxtBarcodeBinary.GETSUBTEXT(ltxtByte,lintBarLoop,1);

        IF ltxtByte = '1' THEN
          lchar := 0
        ELSE
          lchar := 255;

        FOR lintSize := 1 TO pintSize DO BEGIN
          //Putting Pixel: Black or White
          poutBmpHeader.WRITE(lchar,1);
        poutBmpHeader.WRITE(lchar,1);
        poutBmpHeader.WRITE(lchar,1);
        END
      END;

      FOR lintChainFiller := 1 TO ((lintBarLoop* pintSize) MOD 4) DO BEGIN
        //Adding 0 bytes if needed - line end
        lchar := 0;
        poutBmpHeader.WRITE(lchar,1);
      END;
    END;
  END;
END

Note: This only increases performance for horizontal barcodes and only works if the barcode fits in the 1024 Text Variable, but you get the point, you could do it with a bigtext var instead or in nav2013, this restriction is gone anyway ;-)
 

Michael Heydasch's picture

Comment: 

Your contribution is greatly appreciated!

Michael Heydasch's picture

Comment: 

Hello,

You'll find the modified codeunit here ... http://www.mibuso.com/dlinfo.asp?FileID=1456  

Thanks for everyone's contributions!

Michael

Comment: 

Hello Michael,
I do not agree with your assumption that barcode fonts would not render correctly on the RTC reports. You just need to follow below steps to include custom fonts into RDLC report;

  1. First install fonts on the machine. 
  2. Make sure that fonts are of "True Type". If your fonts are Open type then you need to first convert them to TT to be able to visible it in Visual Studio.
  3. Then you need to restart your computer for the font to get embedded into the report.

Hope this tip may be useful to you and save one of the licensed codeunit. :)
Thanks!
Techcronus
www.techcronus.com
 
 

Read ArcherPoint's Blog Follow us on Twitter Follow us on Facebook Follow us on LinkedIn Link to our RSS feed Join us on Google+ Watch us on YouTube
Get Help Now