Skip to content

Barcode

A barcode represents data associated with an object in a form that optical machines can read. Early barcode systems encoded data through varying widths and spacing of parallel lines—these are linear or one-dimensional (1D) barcodes. Barcodes later evolved into two-dimensional (2D) geometric patterns such as rectangles, dots, and hexagons. Although 2D systems use a series of symbols, they are still commonly called barcodes. Barcodes were originally scanned by dedicated optical scanners called barcode readers; scanners and decoding software are now widely used on desktop printers, smartphones, and other devices. Foxit PDF SDK provides APIs to generate barcode bitmaps from a given string. The table below lists the barcode types supported by Foxit PDF SDK.

Barcode TypeCode39Code128EAN8UPCAEAN13ITFPDF417QR
Dimension1D1D1D1D1D1D2D2D

Generate a Barcode Bitmap from a String

c++
#include "include/common/fs_common.h"
#include "include/common/fs_barcode.h"

using namespace foxit;
using namespace foxit::common;
using foxit::common::Library;
...

// Strings used as barcode content.
WString sz_code_string = L"TEST-SHEET";
  
// Barcode format types.
Barcode::Format code_format = Barcode::e_FormatCode39;

//Format error correction level of QR code.
Barcode::QRErrorCorrectionLevel sz_qr_level = Barcode::e_QRCorrectionLevelLow;
  
//Image names for the saved image files for QR code.
WString bmp_qr_name = L"/QR_CODE_TestForBarcodeQrCode_L.bmp";

// Unit width for barcode in pixels, preferred value is 1-5 pixels.
int unit_width = 2;

// Unit height for barcode in pixels, preferred value is >= 20 pixels.
int unit_height = 120;

Barcode barcode;
Bitmap bitmap = barcode.GenerateBitmap(sz_code_string, code_format, unit_width, unit_height, sz_qr_level);
...
C
#include "include/fs_basictypes_c.h"
#include "include/fs_common_c.h"
#include "include/fs_barcode_c.h"
...

// Strings used as barcode content.
const wchar_t* sz_code_string = L"TEST-SHEET";
  
// Barcode format types.
FSFormat code_format = e_FSFormatCode39;

//Format error correction level of QR code.
FSQRErrorCorrectionLevel sz_qr_level = e_FSQRCorrectionLevelLow;
  
//Image names for the saved image files for QR code.
const wchar_t* bmp_qr_name = L"/QR_CODE_TestForBarcodeQrCode_L.bmp";

// Unit width for barcode in pixels, preferred value is 1-5 pixels.
int unit_width = 2;

// Unit height for barcode in pixels, preferred value is >= 20 pixels.
int unit_height = 120;

FS_BARCODE_HANDLE barcode;
FSDK_Barcode_Create(barcode);
FS_BITMAP_HANDLE bitmap;
FSDK_Barcode_GenerateBitmap(barcode, sz_code_string, code_format, unit_width, unit_height, sz_qr_level, &bitmap);
...
java
import com.foxit.sdk.common.Barcode;
...

// Strings used as barcode content.
String codeStr = "TEST-SHEET"
  
// Barcode format types.
int codeFormat = Barcode.e_FormatCode39;

// Format error correction level of QR code.
int qrLevel = Barcode.e_QRCorrectionLevelLow;
  
// Image names for the saved image files for QR code.
String bmpQrName = "/QR_CODE_TestForBarcodeQrCode_L.bmp";

// Unit width for barcode in pixels, preferred value is 1-5 pixels.
int unitWidth = 2;

// Unit height for barcode in pixels, preferred value is >= 20 pixels.
int unitHeight = 120;

Barcode barcode = new Barcode();
Bitmap bitmap = barcode.generateBitmap(codeStr, codeFormat, unitWidth, unitHeight, qrLevel);
...
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    #replace with the python2 lib path
    site.addsitedir('../../../')
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *
...

# Strings used as barcode content.
sz_code_string = "TEST-SHEET"
  
# Barcode format types.
code_format = Barcode.e_FormatCode39

#Format error correction level of QR code.
sz_qr_level = Barcode.e_QRCorrectionLevelLow
  
#Image names for the saved image files for QR code.
bmp_qr_name = "/QR_CODE_TestForBarcodeQrCode_L.bmp"

# Unit width for barcode in pixels, preferred value is 1-5 pixels.
unit_width = 2

# Unit height for barcode in pixels, preferred value is >= 20 pixels.
unit_height = 120

barcode = Barcode() 
bitmap = barcode.GenerateBitmap(sz_code_string, code_format, unit_width, unit_height, sz_qr_level)
objc
#include "FSPDFObjC.h"
...

// Strings used as barcode content.
NSString *code_string = @"TEST-SHEET";
// Barcode format types.
FSBarcodeFormat code_format = FSBarcodeFormatCode39;
// Format error correction level of QR code.
FSBarcodeQRErrorCorrectionLevel qr_level = FSBarcodeQRCorrectionLevelLow;
// Unit width for barcode in pixels, preferred value is 1-5 pixels.
int unitWidth = 2;
// Unit height for barcode in pixels, preferred value is >= 20 pixels.
int unitHeight = 120;

FSBarcode *barcode = [[FSBarcode alloc] init];
FSBitmap *bitmap = [barcode generateBitmap: code_string format:code_format unit_width:unit_width unit_height:unit_height level:qr_level];
...
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");
...

// Strings used as barcode content.
let sz_code_string = "TEST-SHEET";

// Barcode format types.
let code_format = FSDK.Barcode.e_FormatCode39;

// Format error correction level of QR code.
let sz_qr_level = FSDK.Barcode.e_QRCorrectionLevelLow;

// Image names for the saved image files for QR code.
let bmp_qr_name = "/QR_CODE_TestForBarcodeQrCode_L.bmp";

// Unit width for barcode in pixels, preferred value is 1-5 pixels.
let unit_width = 2;

// Unit height for barcode in pixels, preferred value is >= 20 pixels.
let unit_height = 120;

let barcode = new FSDK.Barcode();
let bitmap = barcode.GenerateBitmap(sz_code_string, code_format, unit_width, unit_height, sz_qr_level);
csharp
using foxit;
using foxit.common;
using foxit.common.fxcrt;
...

// Strings used as barcode content.
String sz_code_str = "TEST-SHEET";

// Barcode format types.
Barcode.Format sz_code_format = Barcode.Format.e_FormatCode39;

//Format error correction level of QR code.
Barcode.QRErrorCorrectionLevel qr_level = Barcode.QRErrorCorrectionLevel.e_QRCorrectionLevelLow;

//Image names for the saved image files for QR code.
String sz_bmp_qr_name = "/QR_CODE_TestForBarcodeQrCode_L.bmp";

// Unit width for barcode in pixels, preferred value is 1-5 pixels.
int unit_width = 2;

// Unit height for barcode in pixels, preferred value is >= 20 pixels.
int unit_height = 120;

Barcode barcode;
Barcode barcode = new Barcode();

foxit.common.Bitmap bitmap = barcode.GenerateBitmap(sz_code_str, sz_code_format, unit_width, unit_height, qr_level);
...
go
import (
. “foxit.com/fsdk”
)
...

# Strings used as barcode content.
sz_code_string := "TEST-SHEET"
  
# Barcode format types.
code_format := BarcodeE_FormatCode39

#Format error correction level of QR code.
sz_qr_level := BarcodeE_QRCorrectionLevelLow
  
#Image names for the saved image files for QR code.
bmp_qr_name := "/QR_CODE_TestForBarcodeQrCode_L.bmp"

# Unit width for barcode in pixels, preferred value is 1-5 pixels.
unit_width := 2

# Unit height for barcode in pixels, preferred value is >= 20 pixels.
unit_height := 120

barcode := NewBarcode() 
bitmap := barcode.GenerateBitmap(sz_code_string, code_format, unit_width, unit_height, sz_qr_level)
...