Generating Barcodes
MaSH can generate barcodes from data. These barcodes can then be added to other files or saved as images. You can access the MaSH barcodes library using mash.barcodes.
Natural
# List the types of barcodes that MaSH can generate
printline mash.barcodes.types
Standard
# List the types of barcodes that MaSH can generate
printline(mash.barcodes.types)
Output
Array [
"type_australia_post_redirection",
"type_australia_post_reply_paid",
"type_australia_post_routing",
"type_australia_post_standard",
"type_aztec_code",
"type_aztec_runes",
"type_channel_code",
"type_codabar",
"type_codablock_f",
"type_code_2_of_5",
"type_code_2_of_5_datalogic",
"type_code_2_of_5_iata",
"type_code_2_of_5_industrial",
"type_code_11",
"type_code_16k",
"type_code_32",
"type_code_39",
"type_code_39_plus",
"type_code_49",
"type_code_93",
"type_code_128",
"type_code_128_subset_b",
"type_code_one",
"type_composite_ean",
"type_composite_gs1_128",
"type_composite_gs1_databar_14",
"type_composite_gs1_databar_14_expanded_stacked",
"type_composite_gs1_databar_14_stacked",
"type_composite_gs1_databar_14_stacked_omnidirectional",
"type_composite_gs1_databar_expanded",
"type_composite_gs1_databar_limited",
"type_composite_upc_a",
"type_composite_upc_e",
"type_daft_code",
"type_data_matrix",
"type_deutshe_post_leit",
"type_dot_code",
"type_dutch_post_kix_code",
"type_ean_13",
"type_ean_14",
"type_ean_plus",
"type_fim",
"type_flattermarken",
"type_gs1_128",
"type_gs1_databar_14",
"type_gs1_databar_14_stacked",
"type_gs1_databar_14_stacked_omnidirectional",
"type_gs1_databar_expanded",
"type_gs1_databar_expanded_stacked",
"type_gs1_databar_limited",
"type_grid_matrix",
"type_han_xin",
"type_hibc_aztec_code",
"type_hibc_code_39",
"type_hibc_code_128",
"type_hibc_datamatrix",
"type_hibc_micro_pdf_417",
"type_hibc_pdf_417",
"type_hibc_qr_code",
"type_isbn",
"type_itf_14",
"type_japanese_post_code",
"type_korea_post",
"type_interleaved_2_of_5",
"type_logmars",
"type_maicode",
"type_micro_pdf_417",
"type_micro_qr_code",
"type_msi_plessy",
"type_nve_18",
"type_pdf_417",
"type_pdf_417_truncated",
"type_pharmacode_1_track",
"type_pharmacode_2_track",
"type_planet",
"type_plessy_code",
"type_postnet",
"type_pzn",
"type_qr_code",
"type_royal_mail_4_state",
"type_telepen_alpha",
"type_telepen_numeric",
"type_upc_a",
"type_upc_a_plus_check_digit",
"type_upc_e",
"type_upc_e_plus_check_digit",
"type_usps_onecode"
]
Code Objects
To create a new barcode we first call the code method on the mash.barcodes library.
Natural
set myCode to mash.barcodes.code()
printline myCode
Standard
set myCode = mash.barcodes.code()
printline(myCode)
Output
Barcode {
"data": null,
"format": "png",
"scale": 1,
"type": "type_code_128"
}
Properties
data
data: string get/set
The data to be encoded inside the barcode.
format
format: string get/set
The image format for the generated barcode. Either png or svg.
scale
scale: number get/set
The scale for the generated barcode.
Notes
The scale is a multiple of the default X-dimension. The scale is multiplied by 2 before being applied. The default scale is 1. For PNG output, the default X-dimension is 2 pixels.
type
type: string get/set
The type of barcode to be generated.
Notes
You can get a list of all types by running
printline mash.barcodes.typesfrom the MaSH console.
Saving barcodes
To save a barcode as a file simply pass it as the data parameter to File.write.
Natural
set outputFolder to mash.file(8, "barcodes/output")
set barcode to mash.barcodes.code()
set barcode.data to "Hello from mash"
set barcodeFile to outputFolder.write("code.png", barcode)
printline barcodeFile
Standard
outputFolder = mash.file(8, "barcodes/output")
barcode = mash.barcodes.code()
barcode.data = "Hello from mash"
barcodeFile = outputFolder.write("code.png", barcode)
printline(barcodeFile)
Output
File {
"name": "code.png",
"path": "barcodes/output/code.png",
"modified": "2022-02-17T17:15:58+00:00",
"size": 180,
"is_dir": false,
"mimetype": "image/png",
"hidden": false,
"extra": [],
"share": {
"id": 8,
"name": "Generated Data"
}
}