ByteScout BarCode Generator SDK - Microsoft Word - Add Barcode to Word Document in C# - ByteScout

ByteScout BarCode Generator SDK – Microsoft Word – Add Barcode to Word Document in C#

  • Home
  • /
  • Articles
  • /
  • ByteScout BarCode Generator SDK – Microsoft Word – Add Barcode to Word Document in C#

How to add barcode to word document in c# in Microsoft Word using ByteScout Barcode SDK

How to code in Microsoft Word to add barcode to word document in c# with this step-by-step tutorial

Learn how to add barcode to word document in c# in Microsoft Word with this source code sample. What is ByteScout Barcode SDK? It is the robost SDK that generates high quality barcode images and pdf. Can generate all popular types of barcodes from QR Code, Code 39, Code 128, UPC, GS1, GS-128, PDF417, Datamatrix to more exotic barcode types. Fully customizable fonts, colors, print sizes. Includes special functions to ensure output quality, and tools for adding barcodes to new or existing pdf files and images. It can help you to add barcode to word document in c# in your Microsoft Word application.

The SDK samples like this one below explain how to quickly make your application do add barcode to word document in c# in Microsoft Word with the help of ByteScout Barcode SDK. In your Microsoft Word project or application you may simply copy & paste the code and then run your app! Further enhancement of the code will make it more vigorous.

Trial version of ByteScout Barcode SDK is available for free. Source code samples are included to help you with your Microsoft Word app.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Program.cs
      
/* IMPORTANT: Copy input.doc to your my documents folder and change the path to "input.doc" below Word requires to provide absolute path to input files */ using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Text; using System.Windows.Forms; using Bytescout.BarCode; namespace InsertIntoMicrosoftWordDocument { class Program { [STAThread] static void Main(string[] args) { // Create new barcode Barcode barcode = new Barcode(); // Set symbology barcode.Symbology = SymbologyType.Codabar; // Set value barcode.Value = "123456"; // Add checksum to barcode barcode.AddChecksum = true; // Create word instance Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application(); // Hide word appWord.Visible = false; // Create missing object object mis = System.Reflection.Missing.Value; // Template file - change to the appropraite path where you copied input.doc object fileInput = @"C:\input.doc"; // Template file - change to the appropraite path where you copied input.doc object fileOutput = @"C:\output.doc"; // Open document Microsoft.Office.Interop.Word.Document docWord = appWord.Documents.Open(ref fileInput, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis); // Set bookmark name object bookmarkName = "MyBookmark"; // Get bookmark location Microsoft.Office.Interop.Word.Range bookmarkLocation = docWord.Bookmarks.get_Item(ref bookmarkName).Range; // Get barcode image Bitmap image = (Bitmap)barcode.GetImage(); // Copy image to the clipboard Clipboard.SetDataObject(image); // Paste barcode image to the document bookmarkLocation.Paste(); // Save to the new document docWord.SaveAs(ref fileOutput, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis, ref mis); // We needn't save changes object saveChanges = false; // Close word application appWord.Quit(ref saveChanges, ref mis, ref mis); // Release COM object System.Runtime.InteropServices.Marshal.ReleaseComObject(appWord); } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Barcode SDK Home Page

Explore ByteScout Barcode SDK Documentation

Explore Samples

Sign Up for ByteScout Barcode SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Barcode SDK Home Page

Explore ByteScout Barcode SDK Documentation

Explore Samples

Sign Up for ByteScout Barcode SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next