Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
10.1
10.2
10.3
10.4
10.5
11.0
11.1
11.2
11.3
11.4
Statistic
FMM
Blog
Generates a barcode.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
Barcode | 3.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example | Flags |
---|---|---|---|
symbology | The symbology to use. e.g. EANX for EAN-13. Another possibility is to lookup the symbology code in the zint manual and pass the number here. EANX is 13 for example. |
"EANX" | |
Text | The text to encode in the barcode. | "12345" | |
width | The desired width of the barcode in pixels. Zero gives the auto size. |
0 | Optional |
height | The desired height of the barcode in pixels. Zero gives the auto size. |
0 | Optional |
rotation | The rotation. Can be 0, 90, 180 or 270. | 0 | Optional |
scale | The scale of the target image. Please use at least 4 for printing the barcode. |
1.0 | Optional |
Transparent | 0: black on white 1: black on transparent background 2: white on black (new in 7.2) 3: white on transparent background (new in 7.2) |
1 | Optional |
ShowText | Whether to show text. Use 0 to hide text or 1 to show text. | 1 | Optional |
Encoding | The text encoding for text parameter. Default is UTF-8. Possible encoding names: ANSI, ISO-8859-1, Latin1, Mac, Native, UTF-8, DOS, Hex, Base64 or Windows. More listed in the FAQ. |
UTF8 | Optional |
Returns GMImage reference or error.
Creates UPCA barcode:
MBS( "Barcode.Generate"; "UPCA"; "72527270270")
Create ISDN 9780271016368 barcode with EAN:
MBS( "Barcode.Generate"; "EANX"; "978027101636")
Make a barcode and store it as PNG in a container:
Set Variable [$image; Value:MBS( "Barcode.Generate"; "UPCA"; "72527270270")]
If [MBS("Iserror") = 0]
Set Field [MyTable::BarCodeContainer; MBS( "GMImage.WriteToPNGContainer"; $image; "barcode.png" )]
Set Variable [$r; Value:MBS("GMImage.Release"; $image)]
Else
Set Field [MyTable::BarCodeContainer; ""]
End If
Generate EAN 128
MBS( "Barcode.Generate"; "EAN128"; "[00]993262210000005384")
Generate UPCA barcode:
Set Variable [ $Barcode ; Value: MBS( "Barcode.Generate"; "UPCA"; "76837100000"; 0; 0; 0; 1; 1; 1; "UTF8" ) ]
If [ MBS( "IsError" ) = 0 ]
Set Field [ test::Barcode ; MBS("GMImage.WriteToPNGContainer"; $Barcode; "768371000004.png") ]
Set Variable [ $r ; Value: MBS("GMImage.Release"; $Barcode) ]
Else
Set Field [ test::Barcode ; "" ]
End If
Create a barcode and change color to red:
Set Field [Barcode Generation::Image; ""]
Set Variable [$img; Value:MBS("Barcode.Generate"; Barcode Generation::Symbology; Barcode Generation::Text)]
If [GetAsNumber($img) > 0]
Set Variable [$r; Value:MBS("GMImage.SetType"; $img; 7)]
Set Variable [$r; Value:MBS( "GMImage.ReplaceColor"; $img; "black"; "red"; 3)]
Set Field [Barcode Generation::Image; MBS( "GMImage.WriteToPNGContainer"; $img; "barcode.png")]
Set Variable [$r; Value:MBS( "GMImage.Release"; $img )]
End If
Create a data matrix barcode with size 10 and return as container:
Let ( [
// set options for Size 10 (32x32) square for data matrix
r = MBS("Barcode.SetOptions"; 0; 10; 100);
// create a data matrix barcode
p = MBS("Barcode.Generate"; "DATAMATRIX"; "12818670,3,1" ; 0; 0; 0; 4);
// success?
e1 = MBS("IsError");
// save as PNG
image = MBS( "GMImage.WriteToPNGContainer"; p; "barcode.png" );
// success?
e2 = MBS("IsError");
// free image from memory
r = MBS("GMImage.Release"; p)
// return container if no error
]; If(e1 = 0 and e2 = 0; image; "") )
Generate Maxicode with mode=4:
Set Field [Barcode Generation::Image; ""]
Set Variable [$img; Value:MBS("Barcode.SetOptions"; 4)]
Set Variable [$img; Value:MBS("Barcode.Generate"; "MAXICODE"; "A MaxiCode Message in Mode 4")]
If [MBS("IsError") = 0]
Set Field [Barcode Generation::Image; MBS( "GMImage.WriteToPNGContainer"; $img; "barcode.png")]
Set Variable [$r; Value:MBS( "GMImage.Release"; $img )]
End If
Example for Maxicode creation, e.g. for UPS:
Set Variable [ $p ; Value: "LS97TF 826004" // primary text ]
Set Variable [ $t ; Value: "[)>{RS}01{GS}961Z42015596{GS}UPSN{GS}123W45{GS}339{GS}{GS}1/1{GS}1{GS}N{GS}{GS}LEEDS{GS}{RS}{EOT}" ]
Set Variable [ $t ; Value: Substitute($t; "{EOT}"; Char(4)) ]
Set Variable [ $t ; Value: Substitute($t; "{RS}"; Char(30)) ]
Set Variable [ $t ; Value: Substitute($t; "{GS}"; Char(29)) ]
Set Variable [ $r ; Value: MBS("Barcode.SetOptions"; 3) ]
// Set Variable [ $r ; Value: MBS( "Barcode.SetInputMode"; "data" ) ]
Set Variable [ $r ; Value: MBS( "Barcode.SetInputMode"; "unicode" ) ]
Set Variable [ $r ; Value: MBS("Barcode.SetPrimary"; $p) ]
Set Variable [ $img ; Value: MBS("Barcode.Generate"; "maxicode"; $t) ]
Set Field [ Barcode Generation::Image ; MBS( "GMImage.WriteToPNGContainer"; $img ) ]
Set Variable [ $r ; Value: MBS("GMImage.Release"; $img) ]
Create barcode and crop it:
Set Field [ Barcode Generation::Image ; "" ]
Set Variable [ $img ; Value: MBS("Barcode.Generate"; Barcode Generation::Symbology; Barcode Generation::Text) ]
If [ MBS("IsError") = 0 ]
Set Variable [ $ImageHeight ; Value: MBS("GMImage.GetHeight"; $img) ]
Set Variable [ $ImageWidth ; Value: MBS("GMImage.GetWidth"; $img) ]
# calculate the crop rectangle
Set Variable [ $w ; Value: $ImageWidth ]
Set Variable [ $h ; Value: $ImageHeight ]
Set Variable [ $x ; Value: 0 ]
Set Variable [ $y ; Value: $ImageHeight - 50 ]
# crop
Set Variable [ $r ; Value: MBS("GMImage.Crop"; $img; $w & "x" & $h & "+" & $x & "+" & $y) ]
Set Field [ Barcode Generation::Image ; MBS( "GMImage.WriteToPNGContainer"; $img; "barcode.png") ]
Set Variable [ $r ; Value: MBS( "GMImage.Release"; $img ) ]
End If
Create barcode and cut away top half to get wider EAN codes:
Set Field [ Barcode Generation::Image ; "" ]
Set Variable [ $img ; Value: MBS( "Barcode.Generate"; /* Generates a barcode. */ Barcode Generation::Symbology; /* The symbology to use. e.g. EANX for EAN-13. Another possibility is to lookup the symbology code in the zint manual and pass the number here. EANX is 13 for example.e.g.… ]
If [ MBS("IsError") = 0 ]
# crop to top half
Set Variable [ $h ; Value: MBS("GMImage.GetHeight"; $img) ]
Set Variable [ $w ; Value: MBS("GMImage.GetWidth"; $img) ]
Set Variable [ $r ; Value: MBS("GMImage.Crop"; $img; $w & "x" & ($h/2) & "+0+" & ($h/2)) ]
Set Field [ Barcode Generation::Image ; MBS( "GMImage.WriteToPNGContainer"; $img; "barcode.png") ]
Set Variable [ $r ; Value: MBS( "GMImage.Release"; $img ) ]
End If
Create Code39 barcode in Let statement:
Let ( [
// create a Code39 barcode
p = MBS("Barcode.Generate"; "CODE39"; $Stock ; 160 ; 25 ; 0 ; 2 ; 1 ; 0);
// success?
e1 = MBS("IsError");
// save as PNG
image = MBS( "GMImage.WriteToPNGContainer"; p; "barcode.png" );
// success?
e2 = MBS("IsError");
// free image from memory
r = MBS("GMImage.Release"; p)
// return container if no error
]; If(e1 = 0 and e2 = 0; image; "") )
Create a CMYK picture for barcode:
Set Variable [ $img ; Value: MBS( "Barcode.Generate"; /* Generates a barcode. */
Barcode Generation::Symbology; /* The symbology to use. e.g. EANX for EAN-13.
Another possibility is to lookup the symbology code in the zint manual and pass the number here. EANX is 13 for example.e.g. "EANX" */
Barcode Generation::Text; /* The text to encode in the barcode.e.g. "12345" */
0; /* Optional; The desired width of the barcode in pixels. Zero gives the auto size.e.g. 0 */
0; /* Optional; The desired height of the barcode in pixels. Zero gives the auto size.e.g. 0 */
0; /* Optional; The rotation. Can be 0, 90, 180 or 270.e.g. 0 */
4; /* Optional; The scale of the target image.e.g. 1.0 */
0; /* Optional; 0: black on white */
1; /* Optional; Whether to show text. Use 0 to hide text or 1 to show text.e.g. 1 */
"UTF-8") /* Optional; The text encoding for text parameter.
Default is UTF-8.e.g. UTF8 */]
If [ MBS("IsError") = 0 ]
Set Variable [ $r ; Value: MBS( "GMImage.SetColorSpace"; $img; 10 ) ]
Set Variable [ $r ; Value: MBS( "GMImage.ReplaceColor"; $img; "RGB 1 1 1 1"; "RGB 0 0 0 1"; 10) ]
Set Variable [ $r ; Value: MBS( "GMImage.SetQuality"; $img; 100 ) ]
Set Field [ Barcode Generation::Image ; MBS( "GMImage.WriteToJPEGContainer"; $img; "barcode.jpg") ]
Set Variable [ $r ; Value: MBS( "GMImage.Release"; $img ) ]
End If
Generate code for US Postal Office (USPS):
MBS( "Barcode.Generate"; "OneCode"; "01234567094987654321-012345678")
Created 18th August 2014, last changed 24th November 2020
Barcode.EANChecksum - Barcode.GenerateJSON
Feedback: Report problem or ask question.