Python Barcode Font Encoder | Tutorial

Python 3 font encoders are provided with the purchase of a Developer License or above for the following font packages:

Supported Operating Systems (Python 3)

  • Windows Vista and newer for Python 3.7, Windows XP and newer for Python 2.7
  • Linux
  • FreeBSD 10 and newer
  • MacOS Leopard (macOS 10.6, 2008) and newer
  • Android API 24
  • OpenBSD
  • NetBSD
  • Solaris, OpenIndiana
  • AIX

Installation | Tutorial

This tutorial explains how to import the Python Font Encoder, read and encode data, and output the encoded data to a text file. However, the font encoders provided may be used for several other purposes. More specifically, this tutorial formats data for Code 128 Fonts with the (.py) font encoder file in Visual Studio. The Python Font Encoder (.py) files are located in the "Python Font Encoder" folder of the developer-licensed zip file.

  1. Purchase, download, and install the appropriate barcode fonts by running the setup EXE file provided in the font package. Download and extract the Developer Tools.
  2. Open Visual Studio: Select File - New - Project.
    Create a new project in Python.
  3. Select - Python Application. Name the project and select OK.
  4. In the Solution Explorer, right-click Python Project, then select Add - Existing Item.
    Add an existing item to the Python project.
  5. Search for and select the .py file located in the IDAutomation_Python folder in the Developer Tools for the barcode type to create. In this example, it is the IDAutomation_Python_FontEncoder_Code128Auto.py.
    Select the symbology .py function to encode the barcode.
  6. Right-click the .py file and Set as Startup File.
    Set the .py function as the startup file.
  7. In the project's directory, create a data.txt file to include data to encode.
    Create the text file of data to encode.
  8. In the same directory, create an encodeddata.txt file. The goal of this example is to use Python code to read data from a file, encode it, and save the encoded data to another file.
    Create a file to house the encoded data.
  9. Scroll to the bottom of the code and enter:
    Add the following #Call Function code to the end of the preexisting code in Python.

    Code to copy:

    #CALL FUNCTION
    fd = open("data.txt","r") #opens data.txt file
    fe = open("encodeddata.txt","r+") #opens encodeddata.txt file
    fe.write('Encoded Data for Code128:\r') #output file hearder
    for line in fd: #for loop to loop through values in data.txt
    fe.write(idautomationCode128(line.rstrip(),0,0)) #writes encoded data to encodeddata.txt file
    fe.write('\r')
    fd.close() #close files
    fe.close()
  10. Save the project and run the application.
  11. Review the encoded data.
    Verify that the data is encoded in the text file.

Alternate call function option for encoding data directly in the console window:

#CALL FUNCTION IN CONSOLE WINDOW

#print(idautomationCode128("123456",0,0))