# generateBarcode

## Description

Creates a machine-readable code in the form of numbers and a pattern of parallel lines of varying widths.

## Input / Parameter

| Name        | Description                                  | Input Type | Default | Options | Required |
| ----------- | -------------------------------------------- | ---------- | ------- | ------- | -------- |
| type        | The type of barcode.                         | Text       | CODE128 | -       | No       |
| fontSize    | The font size of the barcode.                | Number     | 20      | -       | No       |
| height      | The height of the barcode.                   | Number     | 100     | -       | No       |
| width       | The width of the barcode.                    | Number     | 2       | -       | No       |
| margin      | The margin of the barcode.                   | Number     | 10      | -       | No       |
| value       | The value of the barcode.                    | Text       | -       | -       | Yes      |
| displayText | To display text or not.                      | Boolean    | true    | -       | No       |
| text        | The text to display.                         | Text       | -       | -       | No       |
| bold        | Bolds the text.                              | Text       | -       | -       | No       |
| italic      | Italicizes the text.                         | Text       | -       | -       | No       |
| textAlign   | To align text or not.                        | Text       | center  | -       | No       |
| extra       | Additional data to be used in the callbacks. | Any        | -       | -       | No       |

## Output

| Description                               | Output Type |
| ----------------------------------------- | ----------- |
| Returns the base64 barcode image pattern. | String/Text |

## Example

In this example, we will generate a barcode and display it in an image component.

### Steps

1. Drag a `button` component and an `image` component to a page in the editor to display the generated barcode.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-e1bab363d1b570e751703e8351f73a2e600fcf1f%2FgenerateBarcode-step-2.png?alt=media)
2. Call the function `Device.generateBarcode` in the `press` event of the button component and set the required parameters to generate the barcode.

   ```js
   height : 200
   value : aaa
   ```

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-4501646cac1feeca6daf8b88c9c70aac2f073c21%2FgenerateBarcode-step-1.png?alt=media)
3. Call the function `App.setComponentValue` if the function `Device.generateBarcode` runs successfully and set the value to display the barcode in the image component.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-028967e62f037e66539399717b1db63937eeeb27%2FgenerateBarcode-step-3.png?alt=media)
4. Call the function `Log.write` if the function `Device.generateBarcode` does not run successfully and set the value to print the response in the console. Drag a `Log.write` function below the function `App.setComponentValue` as well to print the result in the console.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-31769888df1cac57c6fa0f58a4847c586b83ac3c%2FgenerateBarcode-step-4.png?alt=media)

### Result

1. The image component will display the barcode generated if the function is executed successfuly and the console will print the base64 string of the image if the function is not executed successfully.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-97eaaa776f5bc749e2f42d509c53a8d2b0be25d3%2FgenerateBarcode-result-1.png?alt=media)

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-d65d969ad795ba9b95ab53bc76b5fc8f56df10d8%2FgenerateBarcode-result-2.png?alt=media)
