---
title: "Generating barcodes"
description: "Generate and insert customised barcodes in your documents, controlling their format, size, resolution and default values directly within your template."
canonical_url: "https://resources.docmosis.com/template-tutorials/barcodes"
last_reviewed: 2026-06-08
---

# Generating barcodes

Docmosis can generate and insert barcodes into documents.

Docmosis supports Code 39, Code 128 and ITF 14 formats.

### Inserting barcodes

Inserting barcodes with Docmosis uses a technique similar to inserting images.

To insert a barcode, start by inserting a placeholder image. This placeholder determines the size and position of the barcode in the resulting document.

In the template, mark the placeholder image with a meaningful name, for example "img\_itemNumber".

In Microsoft Word: assign a Bookmark to identify the data used for the barcode's value. 

In LibreOffice: the name of the image is used to identify the data.

To instruct Docmosis to generate a barcode image and replace the placeholder image, the data should include the "value", a ":" colon, and then the required barcode "format", for example (in JSON):

  "itemNumber":"value:format"

  "itemNumber":"90127123:code39"

Docmosis will generate a code39 barcode for the value 90127123\.

### Barcode attributes

Instead of including the format in the data, you can include an optional barcode field within the template to set additional attributes for the barcode. This barcode field can be used to specify the barcode format and other attributes such as DPI.

For example, the following barcode field instructs Docmosis that a barcode using the data "itemNumber" should be in "code39" format: \<\

The barcode field can exist anywhere in the template. When the document is rendered, the value for "itemNumber" will be looked up and used to create the barcode.

The special field \<\\> will be removed from the final document.

### Default values

The  \<\\> field in the template can specify default settings for the barcode, including the value, resolution and more. The format and the value are the most common, so they can be specified as follows: \<\\>.

For example: \<\\> specifies barcode1 to have a value of ABC123 and be of type code128\. These settings will be overridden in the data if they are provided.

Other settings such as the resolution can be specified either as a default in the template\-field or via the data values. These other settings are specified as key\=value pairs.

For example, the resolution (dpi) can be specified by: \<\\>. Such a setting (increased resolution) might be required for a small sized barcode.

# Generating barcodes - related json data

```json
{
  "barcode1": "123355:code39",
  "barcode2": "456735",
  "barcode3": "567435"
}
```

# Generating barcodes - example template syntax

```docmosis
**Barcodes**

Inserting barcodes with Docmosis uses a technique similar to inserting images, except that an optional extra field can be used to specify the attributes of the barcode.

Firstly, a placeholder image is placed in the template to control the positioning of the barcode and then a Microsoft Word Bookmark is assigned to it to identify which piece of data will be used for the value of the barcode.

The above placeholder image has the bookmark “img\_barcode1” assigned. Docmosis will use the value of “barcode1” from the data for the value of the barcode and to find any barcode attributes.

For example, when using the following JSON data:

\
 "barcode1":"123355:code39"

Will generate a barcode of value “123355” using barcode format “Code39”.

**Setting Barcode Attributes**

Using the special Docmosis field: ***\<\\>*** you can set attributes about the barcode from within the template.

The following barcode is set to always use “code39” format by using the special barcode field in template, so that only the barcode value need be provided in data as follows:

| "barcode2":"456735"\<\\> |  |
| --- | --- |

The special field ***\<\\>*** will be removed from the final document.

**Default Values**

Anything about a barcode can be specified in the template. A default value for the barcode may even be set.

| Barcode3 field to set 111111 as default\<\\> | Barcode4 field to set 222222 as default\<\\> |
| --- | --- |
| Data: "barcode3":"567435" | Data: (barcode4 not in data) |
|  |  |

**Detailed Configuration**

Further settings available for barcode output, including but not limited to:

Up to 1200dpi resolution

dpi\=1200

\<\\>

Rotation

orientation\=180

\<\\>

Font size or removal

fontSize\=5

\<\\>

fontSize\=0

\<\\>
```