How to create, customize barcode with specified
dimension width/height in C#?


How to generate linear, 2d barcode images in C# asp.net, WPF with C# source code

Create, Print barcode labels in C# ASP.NET Web, WinForms, WPF desktop application with free C# source code project







In this page, you will learn how to install C# Barcode Generator library into your Visual Studio .NET projects through downloaded zip file or NuGet package.

How to create linear, 2d barcodes in ASP.NET and Windows application using C#

  1. Download .NET Barcode Generator Suite
  2. Install C# library to create barcodes in .NET Projects
  3. Step by Step Tutorial


































Quick to create barcode with specified width & height using C#

Top

QR Code dimension width & height

  • Create a new QRCode object with data message set
  • With property BarcodeWidth to 1500 pixels. The generated QR Code square will be 1500 pixels in width and height.
            QRCode barcode = new QRCode();
            barcode.Data = "QR Code";
            barcode.BarcodeWidth = 1500; // 1500 pixels
            barcode.drawBarcode("C://Output//OnBarcode.com//csharp-barcode-size-qrcode.png");



Data Matrix 2d barcode dimension width & height

  • Create a new DataMatrix object with 2d data text encoding
  • With property BarcodeWidth to 900 pixels. The generated Data Matrix square will be 900 pixels in width and height.
            DataMatrix barcode = new DataMatrix();
            barcode.Data = "Data Matrix";
            barcode.BarcodeWidth = 900; // 900 pixels / points
            barcode.drawBarcode("C://Output//OnBarcode.com//csharp-barcode-size-data-matrix.png");



1D / Linear barcode dimension width & height

  • Create a new Linear object with barcode type as Code 128, and barcode data text encoded.
  • Same as the above sample, set AutoResize to true, UOM (unit of measure) to Inch, Resolution to 900 dpi (dots per inch)
  • With property BarcodeWidth to 1 inch and BarcodeHeight to 0.6 inch. The generated Code 128 rectangle will be 1 inch in width, and 0.6 inch in height.
            Linear barcode = new Linear();
            barcode.Type = BarcodeType.CODE128;
            barcode.Data = "Code 128 - 1234567890";

            barcode.AutoResize = true;
            barcode.UOM = UnitOfMeasure.INCH;
            barcode.Resolution = 900; // 900 dot (pixel) per inch
            barcode.BarcodeWidth = 1; // 1 inch
            barcode.BarcodeHeight = 0.6f;

            barcode.drawBarcode("C://Output//OnBarcode.com//csharp-barcode-size-code128.png");





Advanced Barcode Size Customization Settings

Top

Customze barcode padding area

When you change the size of the barcode in AutoResize mode (AutoResize is true), sometimes you may find some extra space around the barcode.

You can hide the extra space by setting the color of the space to be transparent. Here are the sample code.
            QRCode barcode = new QRCode();
            barcode.Data = "QR Code";
            barcode.AutoResize = true;
            barcode.BarcodeWidth = 300;

            barcode.AutoResizePaddingTransparent = true;

            barcode.drawBarcode("C://Output//OnBarcode.com//csharp-barcode-size-qrcode.png");
The second image below is created when AutoResizePaddingTransparent is false.

1D barcode text area settings

When you change the size of the 1d barcode in AutoResize mode (AutoResize is true), the barcode text area will automatically be resized.

If you need manually adjust the barcode text area settings, such as margin space between text and barcode, text font family or size. You can try the following C# code.
  • Create a barcode with specified width and height using AutoResize mode.
  • Set property AutoResizeBarcodeText to false. Now you can manually apply the barcode text size related options.
  • Set TextMargin to the space between barcode and text
  • Set TextFont with your target text font family and size
            Linear barcode = new Linear();
            barcode.Type = BarcodeType.CODE128;
            barcode.Data = "Code 128 - 1234567890";

            barcode.AutoResize = true;
            barcode.UOM = UnitOfMeasure.INCH;
            barcode.Resolution = 900; // 900 dot (pixel) per inch
            barcode.BarcodeWidth = 1; // 1 inch
            barcode.BarcodeHeight = 0.6f;

            barcode.AutoResizeBarcodeText = false;
            barcode.TextMargin = 0.0333f;
            barcode.TextFont = new Font("OCR-B", 20);

            barcode.drawBarcode("C://Output//OnBarcode.com//csharp-barcode-size-code128-text.png");





Complete barcode size related properties in C# Barcode Generator library

Top
We have listed the complete barcode size customization properties. You can view details here:
List of barcode size customization properties in barcode library










OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.