> For the complete documentation index, see [llms.txt](https://docs.heisenware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.heisenware.com/app-builder/build-backend/functions/utilities/barcode-generation.md).

# Barcode generation

With barcode generation, you can create over 100 types of 1D and 2D barcodes and receive them as base64-encoded PNG images. The utility class provides static functions only, meaning you do not need to create an instance before calling them. The code class name is `Barcode`.

### `generateBarcode`

Creates a barcode image from the specified type, text, and options.

#### Parameters

See the [options reference](https://github.com/bwipp/postscriptbarcode/wiki/Options-Reference) for a full list of available configuration keys.

<table><thead><tr><th width="120">Input</th><th width="120">Key</th><th>Description</th><th width="100">Type</th></tr></thead><tbody><tr><td><code>type</code></td><td></td><td>The barcode type, for example <code>qrcode</code>, <code>code128</code>, <code>ean13</code>, or <code>pdf417</code>. See the full list of <a href="https://github.com/metafloor/bwip-js/wiki/BWIPP-Barcode-Types">supported types</a>.</td><td>string</td></tr><tr><td><code>text</code></td><td></td><td>The text or data to encode into the barcode.</td><td>string</td></tr><tr><td><code>options</code></td><td><code>scale</code></td><td>Sets both the x-axis and y-axis scaling factors. Must be an integer greater than 0.</td><td>integer</td></tr><tr><td></td><td><code>scaleX</code></td><td>The x-axis scaling factor. Must be an integer greater than 0. Default 2.</td><td>integer</td></tr><tr><td></td><td><code>scaleY</code></td><td>The y-axis scaling factor. Must be an integer greater than 0. Defaults to the value of <code>scaleX</code>.</td><td>integer</td></tr><tr><td></td><td><code>width</code></td><td>Bar width in millimeters.</td><td>integer</td></tr><tr><td></td><td><code>height</code></td><td>Bar height in millimeters.</td><td>integer</td></tr><tr><td></td><td><code>includeText</code></td><td>Shows the human-readable text below the barcode. Default false.</td><td>boolean</td></tr><tr><td></td><td><code>textAlign</code></td><td>Alignment of the human-readable text: <code>left</code>, <code>center</code>, <code>right</code>, or <code>justify</code>. Default center.</td><td>string</td></tr><tr><td></td><td><code>rotate</code></td><td>Rotates the image: <code>N</code> (normal), <code>R</code> (right 90 degrees), <code>L</code> (left 90 degrees), or <code>I</code> (180 degrees). Default N.</td><td>string</td></tr><tr><td></td><td><code>binaryText</code></td><td>By default the text string is encoded as UTF-8 binary bytes. If the text is already 8-bit encoded, set this to true to disable that behavior. Default false.</td><td>boolean</td></tr><tr><td></td><td><code>padding</code></td><td>Space generated around the barcode.</td><td>integer</td></tr><tr><td></td><td><code>barColor</code></td><td>Bar color as an RGB, RRGGBB, or CCMMYYKK hex value, for example <code>0F7180</code>.</td><td>string</td></tr><tr><td></td><td><code>textColor</code></td><td>Text color as an RGB, RRGGBB, or CCMMYYKK hex value.</td><td>string</td></tr><tr><td></td><td><code>backgroundColor</code></td><td>Background color as an RGB, RRGGBB, or CCMMYYKK hex value.</td><td>string</td></tr><tr><td></td><td><code>borderColor</code></td><td>Border color as an RGB, RRGGBB, or CCMMYYKK hex value.</td><td>string</td></tr></tbody></table>

#### Output

Returns a base64-encoded string representing the generated PNG image (for example, `iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACt...`). Throws an error if the type or text is invalid.

#### Examples

**Simple QR code**

Generates a standard QR code for a URL.

```yaml
# type
qrcode

# text
https://heisenware.com
```

**Styled Code 128 barcode**

Creates a `code128` barcode, scales it, includes the human-readable text, and applies custom colors.

```yaml
# type
code128

# text
12345678

# options
scale: 3
includeText: true
barColor: 0F7180
textColor: 0F7180
```

**Rotated EAN-13 barcode**

Generates an `ean13` barcode (which requires a 12-digit input) and rotates it 90 degrees to the right.

```yaml
# type
ean13

# text
123456789012

# options
scale: 4
rotate: R
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.heisenware.com/app-builder/build-backend/functions/utilities/barcode-generation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
