How Do I Generate and Print a Barcode from LabVIEW?

Updated May 3, 2018

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base
  • LabVIEW Professional

Issue Details

I would like to generate a barcode in LabVIEW and then print the barcode. However, when I try to print a barcode font from LabVIEW with any of the Print VIs, it comes out distorted from the printer. How do I fix this problem?

Solution

First of all, you need a barcode font. If you do not have one you can download free barcode fonts from the internet. The font file must be placed in the following location: C:\WINDOWS\Fonts

You can change the font for any string control in LabVIEW to your barcode font. Keep in mind that barcode fonts can differ and some may not include all characters. For more information on using different fonts in LabVIEW see the Related Links section below.



When it comes to printing the barcode fonts, LabVIEW sometimes has difficulty working with them and can produce distorted images. You can successfully print the barcode without distortion by either writing the barcode font to a picture file (i.e. JPEG), then printing that picture file, or by using the Report Generation Toolkit to write the barcode text to a report and then print the report.

Writing a Barcode to a Picture File
  1. From the block diagram, right-click on the control or indicator that contains the barcode font and select Create » Invoke Node » Get Image.
  2. Place the Write JPEG File VI (located under Functions » Programming » Graphics & Sound » Graphics Format»Write JPEG File) on the block diagram. Wire the Image Data output of the Invoke Node to the Image Data input of the Write JPEG File function (NOTE: Bitmap and PNG formats will also work). Also wire in the path of where you would like to save the image.
  3. Now that you have a JPEG of the barcode, you can then programmatically print the file. To do this, place the System Exec VI (located under Functions » Connectivity » Libraries & Executables » System Exec) onto the block diagram. Next, wire in a command to print the file. (For example, the string mspaint.exe /p jpeg file path will open the file in Microsoft Paint and print it).
Once completed, your block diagram should look like the image below:



Writing a Barcode to a Report Using Report Generation Toolkit
  1. Use the the Set Report Font.vi to set the font to your desired Barcode Font and desired size. You can manually enter the Font Settings by providing the barcode font name and text size, or change the format settings source to Font Dialog Box to have a dialog box pop up to set the different properties.
  2. Use the Append Report Text.vi to set the text you want to change into a barcode.
  3. Print the report using the Print Report.vi.
Below is an image of using the Report Generation Toolkit VIs printing the text Hello from a Word document:




 

WAS THIS ARTICLE HELPFUL?

Not Helpful