条形码 (Barcode)
条形码用于表示与某个对象相关的数据,该数据可通过光学机器进行读取。最初的条形码系统是通过平行线间宽度和间距的不同来表示数据,可称为线性条形码或一维条形码( 1D)。后来条形码逐渐演变成矩形、点、六边形等 2D 几何图案。虽然 2D 系统使用了一系列符号,但是它们通常也被称为条形码。条形码最初由特定的光学扫描器进行扫描,该光学扫面器被称为条形码读取器。后来扫描器和解释软件成功应用于桌面打印机和智能手机等设备。福昕 PDF SDK 提供了从给定字符串生成条形码位图的应用程序。以下表格列出了福昕 PDF SDK 支持的条形码类型。
条形码类型 | Code39 | Code128 | EAN8 | UPCA | EAN13 | ITF | PDF417 | QR |
---|---|---|---|---|---|---|---|---|
维度 | 1D | 1D | 1D | 1D | 1D | 1D | 2D | 2D |
从字符串生成条形码位图
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);
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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];
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
js
const FSDK = require("@foxitsoftware/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);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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);
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28