1. Products
  2.   Word Processing
  3.   C++
  4.   DocxFactory
 
  

Free C++ API to Create Template-Based Word DOCX Files

A Leading Open-Source Free C++ Word Processing Library allows to Create, Edit, Merge, and Convert Word DOCX Files Programmatically. Add Barcodes Charts, Text, Images and Apply Formatting.

What is DocxFactory?

DocxFactory is a powerful, cross-platform open source C++ library designed for generating Microsoft Word DOCX files (OpenXML format) through template-based document creation. This free library comes with wrappers for multiple programming languages including C#, Java, Python, and Progress 4GL, along with command line tools. What sets DocxFactory apart is its template-driven approach that eliminates the need for developers to understand the complex OpenXML file format. The library has included support for various important word processing features, such as template-based document generation, Insert / remove paragraphs or images, text formatting, work with tables, merge or split cells, manage lists, multi-language support, extensive barcode support, multiple output format support and so on.

DocxFactory is a mature, free, cross-platform C/C++ library (with multi-language wrappers) that simplifies working with Microsoft Word .docx files. The library is cross-platform and smoothly works on major operating systems (Windows, UNIX/Linux) — giving flexibility to deploy on servers, desktop, or embedded systems. The library is licensed under the Apache 2.0 license, making it completely free for both private and commercial use without any feature limitations or time restrictions. Whether you're building enterprise reporting systems, automated document workflows, or simple mail merge applications, DocxFactory provides the tools needed to generate professional documents efficiently.

Previous Next

Getting Started with DocxFactory

The recommend way to install DocxFactory is via GitHub. Please use the following command for a smooth installation.

Install DocxFactory via GitHub

git clone https://github.com/DocxFactory/DocxFactory.git  
You can also download it directly from Aspose product page.

Template-Based Document Generation via C++

The core philosophy of DocxFactory revolves around simplicity. Instead of programmatically constructing documents element by element, you create a template in Microsoft Word—a regular DOCX file with placeholders—and merge your data into it. This approach offers several advantages, such as faster development, WYSIWYG editing, faster development, and so on. Here is a useful example that demonstrates, how to generate new World documents from a temple using C++ library.

How to Create a New Document from Template via C++ Library?

#include "DocxFactory/DocxMerger/DocxMerger.h"
#include "DocxFactory/DocxMerger/DocxMergerItem.h"

// Create a new document from template
DocxFactory::DocxMerger docxMerger;
DocxFactory::DocxMergerItem* item = docxMerger.load("template.docx");

// Set field values
item->setFieldValue("customer.name", "John Smith");
item->setFieldValue("invoice.date", "2024-01-15");
item->setFieldValue("invoice.total", 1250.75);

// Save generated document
docxMerger.save("generated_invoice.docx");

Extensive Barcode Support in DOCX

The open source DocxFactory library supports an extensive range of 1D and 2D barcodes, including Code39, Code128, EAN, UPC, ISBN, Databar, Postal Codes, PDF417, Data Matrix, QR Code, and Maxi Code. Barcodes are inserted as fields in templates and automatically rendered based on the data you provide. This makes it ideal for inventory management systems, shipping and logistics applications, product labeling solutions, document tracking systems, retail point-of-sale integration and so on.

The DocxFactory library can populate chart data dynamically, allowing you to create data-driven visualizations. Charts defined in your template can have their data series updated programmatically, making it possible to generate executive dashboards and analytical reports. The library has included support for complete list of more than 70 chart types available in Microsoft Word, including Column, Line, Pie, Bar, Area, Scatter, Stock, Surface, Doughnut, Bubble, Radar charts and so on. This feature enables dynamic financial reports with real-time data visualization, statistical analysis documents, business intelligence dashboards, scientific research reports, performance tracking documentation and so on.

Advanced Formatting and Styling in DOCX Files

The open source DocxFactory library maintain Word's native formatting while dynamically adjusting styles inside C++ applications. The library has included support for various formating features such as font styles, sizes, and colors, paragraph alignment and spacing, tables with custom borders, headers and footers, page numbers and section breaks, custom styles & themes, and so on. The generated document preserves all formatting from the template, ensuring consistent branding and professional appearance. The following code example shows how developers can apply conditional formatting base on data inside C++ apps.

How to Apply Advanced Formatting and Styling inside Word Documents via C++ Library?



// Advanced Conditional formatting based on data

item->setFieldValue("status.text", "OVERDUE");
item->setFieldValue("status.color", "#FF0000"); // Red color for overdue

// Dynamic table row formatting
for (size_t i = 0; i < invoiceItems.size(); i++) {
    if (i % 2 == 0) {
        item->setFieldValue("items.rowColor", "#F5F5F5");
    }
}