BarCodeUrl()
Generates a barcode based on an input string. Most of the barcode types that the function can generate are linear (one-dimensional), although it can generate two-dimensional Data Matrix and PDF417 codes. The function can’t be used to create QR codes.
You can call this function up to two times per message or landing page.
The BarCodeURL()
function has nine parameters:
valueToConvert
(string): Required. The value that you want to convert into a barcode.barcodeType
(string): Required. The type of barcode to create. See Supported Barcode Types for a list of possible values.width
(number): Required. The width of the barcode in pixels.height
(number): Required. The height of the barcode in pixels.checksumValue
(string): A checksum value for the barcode.boolShowText
(boolean): Iftrue
or1
, the function includes the text ofvalueToConvert
under the barcode.altText
(string): Alternate text to display under the barcode. The function only adds the specified text to the barcode when the value ofboolShowText
isfalse
.rotation
(number): Orientation of the barcode in degrees. Accepted values:0
,90
,180
,270
.boolTransparentBG
(boolean): Iftrue
or1
, the barcode includes a transparent background. Otherwise, the background is white.
The BarCodeUrl()
function supports a variety barcode encoding standards. This table describes the features and limitations of each supported barcode type.
Code | Name | Type | Character Limit | Allowed Characters | Notes |
---|---|---|---|---|---|
codabar | Codabar | Linear | Variable | Uppercase letters A–D, numbers 0–9, and these characters: - $ : / . + | Must begin and end with a letter A–D |
code11 | Code 11 | Linear | Variable | Numbers 0–9 and - | |
code128auto | Code 128 Auto | Linear | Variable | All ASCII characters | |
code128a | Code 128 A | Linear | Variable | Uppercase ASCII characters, numbers 0–9, and ASCII special characters | |
code128b | Code 128 B | Linear | Variable | Uppercase and lowercase ASCII characters, numbers 0–9, and ASCII special characters | |
code128c | Code 128 C | Linear | Variable | Numbers 0–9 | |
code39 | Code 39 | Linear | Variable | Uppercase letters (A–Z), numbers (0-9), spaces, and these characters: - . $ / + % | |
code39ext | Code 39 Extended | Linear | Variable | Any character in the extended ASCII character set | |
code93 | Code 93 | Linear | Variable | Uppercase letters (A–Z), numbers (0-9), spaces, and these characters: - . $ / + % | |
code93ext | Code 93 Extended | Linear | Variable | All ASCII characters | |
datamatrix | Data Matrix | Two-dimensional | 1556 bytes | All extended ASCII characters | Binary encodings aren’t supported |
ean13 | EAN 13 | Linear | 13 digits | Numbers 0–9 | |
ean8 | EAN 8 | Linear | 8 digits | Numbers 0–9 | |
industr25 | Code 25 Industrial | Linear | Variable | Numbers 0–9 | |
interl25 | Code 25 Interleaved | Linear | Variable | Numbers 0–9 | |
msi | MSI Plessey | Linear | Variable | Numbers 0–9 | |
pdf417 | PDF 417 | Two-dimensional | 1108 bytes | All extended ASCII characters | Binary encodings aren’t supported |
upca | UPC A | Linear | 12 digits | Numbers 0–9 | |
upce | UPC E | Linear | 12 digits | Numbers 0–9 | Identical to UPC A in this implementation |
The function lets you specify some barcode types that aren’t supported. If you specify any of the values in this list, the function doesn’t produce an exception, but it also doesn’t output a barcode.
mat25
onecode
plaintext
planet
postnet
telepen
To call the function, pass the string that you want to encode, the barcode type to use, and the width and height of the barcode, along with any optional arguments. Some barcode types, such as EAN 8 or UPC A, only accept a certain number of characters. When you use a non-variable-length barcode type, and you include an incorrect number of characters, the function doesn’t render the barcode.
If you call the function using optional parameters, you must include all of the parameters that precede it. For example, if you want to include the altText
parameter, you must also include the checksumValue
and boolShowText
parameters. In this situation, you can pass empty strings if it's unnecessary to provide a string value. Continuing the example, if it's unnecessary to provide a value for the checksumValue
parameter because the barcode type you selected includes a checksum by default, you can pass an empty string.
To render the barcode, enclose the function code in an HTML <img>
tag. This example creates a Code 128 Auto barcode that includes the URL of the Salesforce website.
The rendered HTML email or landing page includes this barcode.
This example creates a Code 128 Auto barcode in which the encoded data is the URL of the Salesforce website. Rather than print the same text below the barcode, this example uses the altText
parameter to specify a different printed string.
Code 128 Auto barcodes include an internal check digit by default, so you can pass an empty string for the checksumValue
parameter.
The rendered HTML email or landing page includes this barcode.
This example creates a Code 128 Auto barcode that is rotated 90° clockwise.
The rendered HTML email or landing page includes this barcode.