Create PDF417 barcode in PowerBuilder with Fonts

This tutorial illustrates how to create a PDF417 barcode (ISO/IEC 15438:2015) in PowerBuilder with a COM (Component Object Model) library and barcode fonts available in ConnectCode PDF417 barcode package.

Prerequisites

  • PowerBuilder 2021 (or PowerBuilder v12, PowerBuilder 2017, PowerBuilder 2019)
  • ConnectCode PDF417 barcode package is installed

Tutorial on creating a PDF417 barcode in PowerBuilder

1. Launch a Developer Command Prompt for Visual Studio as Administrator. In the Command Prompt, change the directory to the "PDF417COMLibrary" folder.


	cd C:\Program Files (x86)\ConnectCodePDF417\Resource\PDF417COMLibrary		

   

2. Next, use Regasm.exe (Assembly Registration Tool) to register the "PDF417COMLibrary.dll" assembly. When you specify the "/tlb" option, "Regasm.exe" generates and registers a type library describing the types found in the assembly.


	Regasm PDF417COMLibrary.dll /tlb:PDF417COMLibrary.tlb /codebase			

   

If "Regasm.exe" is not available, you can verify whether the following folder exists and add the folder into your PATH. The folder may be different depending on your version of .NET. If you are using an "x86" version of Windows, replace "Framework64" with "Framework".


	C:\Windows\Microsoft.NET\Framework64\v4.0.30319\		
	 
   

3. Launch "PowerBuilder", select the "Target tab" and create a new "Template Application".

4. You can select “SDI application” as the "Application Type" and “None” in Connectivity Options” to create a sample application in your workspace.

5. Click on "w_genapp_main" in the project to launch the designer. From the menu, select the option "Insert->Control->CommandButton" to add a "button" and rename the button to "PDF417". Next, insert a "StaticText" control and layout the components as shown in the screenshot below. Set the background of the "StaticText" control to "White".

A PDF417 barcode (ISO/IEC 15438:2015) can have a row height that is 3x or 4x to its column width. ConnectCode PDF417 barcode package supports both the 3x and 4x row height with the following fonts:

  • CCodePDF417_S3X - PDF417 Barcode Font with a row height of 3x the column width.
  • CCodePDF417_S4X - PDF417 Barcode Font with a row height of 4x the column width.

Select the "StaticText" control, change the Font to "CCodePDF417_S3X" (or "CCodePDF417_S3X_Trial" if you are using the Trial version) and the Font Size to 2 to fit the barcode nicely on the "StaticText" control. The output generated by the "PDF417COMLibrary" will be placed in the "StaticText" control and displayed as a barcode with a "CCodePDF417_S3X" (or "CCodePDF417_S3X") True Type font.

6. Next, double click on the button and add the following script:


OLEObject barcode
int return_code
barcode = CREATE OLEObject
return_code=barcode.ConnectToNewObject("Net.ConnectCode.PDF417COMLibrary")
if return_code<>0 then
	destroy barcode
	messagebox ("Error","PDF417COMLibrary not available")
else
	string result
	string input="12345678"
	int cols = 0
	int errorLevel = -1
	int truncate = 0
	result=barcode.Encode_PDF417(input,cols,errorLevel,truncate)
	st_1.Text=result
	destroy barcode
end if

   

In the source code above, an OLE object is created with the "PDF417COMLibrary". The "Encode_PDF417" method is used to generate the barcode.

First Parameter: Input String

Second Parameter: Number of Columns

  • 0 for Auto or
  • 1 to 30 Columns

Third Parameter: Error Level

  • -1 - Auto Detect Optimal Error Level (Recommended)
  • 0 - Support 2 error codewords. This is the minimum Error Correction Level.
  • 1 - Support 4 error codewords.
  • 2 - Support 8 error codewords.
  • 3 - Support 16 error codewords.
  • 4 - Support 32 error codewords.
  • 5 - Support 64 error codewords.
  • 6 - Support 128 error codewords.
  • 7 - Support 256 error codewords.
  • 8 - Support 512 error codewords. This is the maximum Error Correction Level.

Fourth Parameter: Truncate

The right-hand side of the PDF417 barcode can be truncated (removed) without causing any loss of data. This allows the creation of a barcode that takes up a smaller amount of space than a normal PDF417 barcode.

7. Run the application by going to the menu and then selecting “Run->Select and Run”. Click on the "PDF417" button and see that you get a PDF417 barcode output in the "StaticText" control. If you get an error message saying that "PDF417COMLibrary is not available", check that you have carried step 2 to register the library successfully.