C# Barcode Generator Library
How to generate barcode to Microsoft Word (.docx) file?
How to create, add barcode to Microsoft Word (.docx) document in C# ASP.NET Core, MVC, WinForms, WPF apps?
How to create QR Code barcode to Word document using C#?
The C# sample code below explains how to create, add QR Code barcode image to an existing Microsoft Word (.docx) document using C#.NET.
- Create a new QRCode object, and set the QR Code data message.
- Customize QR Code barcode dpi, width, height options
- Create a new DOCXDocument object from an existing Word file
- Get a new DOCXPage object from the first page of the Word document
- Generate and print QR Code on the DOCXPage object on the specified region
- Save the Word (.docx) file
QRCode barcode = new QRCode();
barcode.Data = "https://www.rasteredge.com";
barcode.AutoResize = true;
barcode.Resolution = 96;
barcode.UOM = UnitOfMeasure.INCH;
barcode.BarcodeWidth = 1.5f;
barcode.BarcodeHeight = 1.5f;
String inputFilePath = @"C:\Input\RasterEdge.com\test-document.docx";
String outputFilePath = @"C:\Output\RasterEdge.com\barcode-qrcode-word.docx";
DOCXDocument doc = new DOCXDocument(inputFilePath);
// Draw the barcode at position (100, 200) in pixels on the 1st page.
DOCXPage page = (DOCXPage)doc.GetPage(0);
barcode.DrawBarcode(page, 120, 200);
doc.Save(outputFilePath);