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,472,280Version:2026.10just 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 IronBarcode
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get a Quote, No Obligation
Your details will always be kept confidential.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Trusted by Millions of Engineers Worldwide
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.10

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronBarCode"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.10

  1. Download and unzip IronBarCode to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronBarCode.dll"

Licenses from $999