Create Barcode in Word in C#, VB.NET

Barcode is formed by several blanks and black stripes with a specified order. It presents the brief information of one product, including manufacturer, product name, category, price etc. At present, barcode is widely used in commodity circulation. Also, people can create barcode in Word and print.

Spire.Doc for .NET, a stand-alone professional .NET Word component, enables users to create barcode in Word by using C#, VB.NET. So, this guide will show you the method about how to create via Spire.Doc for .NET.

At first, you need to install barcode font on your system. Then, add barcode text through invoking p.AppendText(string) method and then set text format properties for it, such as FontName, FontSize, TextColor etc. After running, we can get result as following screenshot.

Create Word Barcode

Download and install Spire.Doc for .NET and then use the following code to create barcode in Word.

[C#]
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace WordBarcode
{
    class BarCode
    {
        static void Main(string[] args)
        {
            //Create Document
            Document document = new Document();
            Paragraph p = document.AddSection().AddParagraph();

            //Add Barcode and Set Format
            TextRange txtRang = p.AppendText("H63TWX11072");
            txtRang.CharacterFormat.FontName = "C39HrP60DlTt";
            txtRang.CharacterFormat.FontSize = 80;
            txtRang.CharacterFormat.TextColor = Color.SeaGreen;

            //Save and Launch
            document.SaveToFile("barcode.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("barcode.docx");
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields

Namespace WordBarcode
    Friend Class BarCode
        Shared Sub Main(ByVal args() As String)
            'Create Document
            Dim document As New Document()
            Dim p As Paragraph = document.AddSection().AddParagraph()

            'Add Barcode and Set Format
            Dim txtRang As TextRange = p.AppendText("H63TWX11072")
            txtRang.CharacterFormat.FontName = "C39HrP60DlTt"
            txtRang.CharacterFormat.FontSize = 80
            txtRang.CharacterFormat.TextColor = Color.SeaGreen

            'Save and Launch
            document.SaveToFile("barcode.docx", FileFormat.Docx)
            System.Diagnostics.Process.Start("barcode.docx")
        End Sub
    End Class
End Namespace

Spire.Doc is a Microsoft Word component, which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF, .NET and Silverlight.