IRONSOFTWAREHOME
Set Barcodes Margins
using IronBarCode;

// Specify Code 128 Format
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128);

// Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode();

// Save it as JPG
barcode.SaveAsJpeg("code128-sample.jpg");
Imports IronBarCode

' Specify Code 128 Format
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128)

' Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode()

' Save it as JPG
barcode.SaveAsJpeg("code128-sample.jpg")
NuGet Download
PM > Install-Package BarCode
Set Barcodes Margins

Set Barcodes Margins

The margins of the barcode are the blank space that surrounds the code. This area is critical for scanner reliability. It enables the scanner to identify where the barcodebeginsandends, thereby separating it from nearby text or graphics. Without proper margins, a scan can fail or misread data. In this code example, we will demonstrate how to set a consistent margin on a barcode with IronBarcode to ensure readability.

3-Step Guide to Setting Barcode Margins

  • using IronBarCode;
  • GeneratedBarcode qrcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode);
  • qrcode.SetMargins(100);

Code Explanation

We first import the IronBarcode library, then we generate a barcode using the BarcodeWriter.CreateBarcode method. We pass two arguments to the method: the string value and the type of the barcode. In the example above, these are "https://ironsoftware.com/csharp/barcode" and BarcodeWriterEncoding.QRCode, respectively.

After creating the GeneratedBarcode object, we call the SetMargins method. We pass it a single integer value, which represents the margin in pixels. In this case, 100 applies a 100-pixel quiet zone to all four sides of the generated QR code.

Discover how to enhance your barcode designs with in-depth Guide!
View on GitHub

Ready to Get Started?

Nuget Downloads 2,422,100Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required