ByteScout simple and easy to understand tutorials are planned to describe the code for both Microsoft Word beginners and advanced programmers. ByteScout Barcode Suite can add barcode to word document in c# with barcode SDK. It can be applied from Microsoft Word. ByteScout Barcode Suite is the set that includes three different SDK products to generate barcodes, read barcodes and read and write spreadsheets: Barcode SDK, Barcode Reader SDK and Spreadsheet SDK.
This prolific sample source code in Microsoft Word for ByteScout Barcode Suite contains various functions and other necessary options you should do calling the API to add barcode to word document in c# with barcode SDK. Simply copy and paste in your Microsoft Word project or application you and then run your app! Enjoy writing a code with ready-to-use sample Microsoft Word codes.
All these programming tutorials along with source code samples and ByteScout free trial version are available for download from our website.
On-demand (REST Web API) version:
Web API (on-demand version)
On-premise offline SDK for Windows:
60 Day Free Trial (on-premise)
/*
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);
}
}
}
60 Day Free Trial or Visit ByteScout Barcode Suite Home Page
Explore ByteScout Barcode Suite Documentation
Explore Samples
Sign Up for ByteScout Barcode Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
60 Day Free Trial or Visit ByteScout Barcode Suite Home Page
Explore ByteScout Barcode Suite Documentation
Explore Samples
Sign Up for ByteScout Barcode Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
also available as: