How to Add Line Breaks in QR Code, Data Matrix, and PDF-417 Barcodes?

2D barcodes are designed to store data in a compact format, and there is no standard way to include line breaks in a QR Code, Data Matrix, or PDF-417 barcode. However, some barcode readers may interpret certain characters as line breaks.

One way to add/simulate line breaks in a QR Code, Data Matrix, or PDF-417 2d barcode is to use a special character or sequence that is recognized by the barcode reader as a line break.​​ For example, you could use the newline character (\n) or a combination of characters such as "<br>" to represent a line break.

In UTF-8 encoding, the line break character is represented as "\n". So, you can include "\n" in the data that you want to encode in the barcode and the barcode reader should interpret it as a line break.​​

Here's an example of how to create a QR Code barcode with line breaks using the CnetSDK .NET Barcode Generator library. This barcoding library also supports 2D barcodes like Data Matrix, Aztec Code, and PDF-417 barcode symbologies.

















In this example, the newline character (\n) is used to separate the lines of text in the text variable. The CnetSDK .NET Barcode Generator library is used to create a QR Code with the specified text, and the options for the QR Code are set to specify the UTF-8 encoding and the error correction level L. Finally, the QR Code barcode image is saved to a file.

When the QR Code is scanned with a barcode reader that recognizes the newline character as a line break, the text will be displayed as three separate lines. Note that not all QR Code barcode readers will recognize the newline character as a line break.

If you want to add line breaks to 2d barcodes in Python, see as follows. It is an example of how you could use the newline character to create a QR Code with multiple lines of text in Python using the qrcode library.





















​In this example, the newline character (\n) is used to separate the lines of text in the text variable. When the QR Code is scanned with a barcode reader that recognizes the newline character as a line break, the text will be displayed as three separate lines. Note that not all QR Code readers will recognize the newline character as a line break.

We hope the above suggestions help you resolve your issue! Besides CnetSDK .NET Barcode Generator library, CnetSDK.com also offers mature .NET PDF barcode generator library and .NET PDF barcode reader library for QR Code, Data Matrix, PDF-417, and Aztec Code.
​​​​Home > Articles How to Add Line Breaks in QR Code, Data Matrix, and PDF-417 Barcodes?​​​​
using CnetSDK.Barcode.Generator.Trial;

// Define the text to encode in QR Code
string text = "Line 1\nLine 2\nLine 3";

// Create a QR Code with the specified text
CSBarcode qrcode = new CSBarcode();
qrcode.BarcodeType = CSBarcodeType.QRCode;
qrcode.BarcodeData = text;

// Set the QR Code barcode options
qrcode.UseUTF8 = true;
qrcode.QRCodeErrorCorrectionLevel = ECLMode.L

// Save the QR Code image to a file
qrcode.CreateBarcode("CnetSDKQRCodeExample.png");

import qrcode

# Define the text to encode
text = "Line 1\nLine 2\nLine 3"

# Create the QR Code
qr = qrcode.QRCode(
version=None,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)

# Add the text to the QR Code
qr.add_data(text)

# Make the QR Code image
img = qr.make_image(fill_color="black", back_color="white")

# Save the image
img.save("qr_code.png")