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
- FreeBSD 10 and newer
- MacOS Leopard (macOS 10.6, 2008) and newer
- Android API 24
- Solaris, OpenIndiana
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.
- 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.
- Open Visual Studio: Select File - New - Project.
- Select - Python Application. Name the project and select OK.
- In the Solution Explorer, right-click Python Project, then select Add -
- 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
- Right-click the .py file and Set as Startup File.
- In the project's directory, create a data.txt file to include data to encode.
- 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.
- Scroll to the bottom of the code and enter:
Code to copy:
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
fd.close() #close files
- Save the project and run the application.
- Review the encoded data.
Alternate call function option for encoding data directly in the console window:
#CALL FUNCTION IN CONSOLE WINDOW