This blog post contains outdated information.
The cited code snippets may be workarounds, and be part of the official API in the meantime.
Converting Markdown to DOCX and PDF in C#
Markdown is a popular, lightweight markup language to create formatted text in a simple way. This article shows how to convert Markdown files to Office Open XML and PDF documents using TX Text Control and Markdig - a powerful and extensible Markdown processor for .NET.

⚠️ Important Update
This article is outdated and no longer reflects the current state of TX Text Control. Markdown import and export is now built directly into TX Text Control packages without the need for third-party packages. To learn how to use the integrated Markdown features, check out our updated guide:
Introducing TXTextControl.Markdown.Core: Import and Export Markdown in TX Text Control
Markdown is a popular, lightweight markup language to create formatted text in a simple way. Specifically for developers, it became a standard to describe projects such as in Readme files in GitHub repositories and other resources.
This article shows how convert Markdown files to Office Open XML and PDF documents using TX Text Control and Markdig - a powerful and extensible Markdown processor for .NET.
Use the following steps to create a console application to convert Markdown to Office Open XML and PDF documents.
Prerequisites
A trial version of TX Text Control .NET Server is required for this tutorial.
- Download Trial Version
Setup download and installation required.
Creating the Application
-
In Visual Studio, create a new Console App.
-
In the Solution Explorer, select the created project and choose Manage NuGet Packages... from the Project main menu. Set the Package source to nuget.org and search for Markdig. Select the package Markdig and click Install.
-
Switch the Package source to Text Control Offline Packages and install the package TXTextControl.TextControl.ASP.SDK.
-
Create a new class named TXMarkdown and paste the following code into the class:
using Markdig; namespace TXTextControl { public static class Markdown { public static byte[] Convert(string markdown, BinaryStreamType binaryStreamType) { var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); var htmlString = Markdig.Markdown.ToHtml(markdown, pipeline); using (ServerTextControl tx = new ServerTextControl()) { tx.Create(); tx.Load(htmlString, StringStreamType.HTMLFormat); byte[] results; tx.Save(out results, binaryStreamType); return results; } } } }
-
Now, you can use this class in your application to convert any Markdown file to an Office Open XML (DOCX) file:
var mdFile = System.IO.File.ReadAllText("sample.md"); byte[] document = TXTextControl.Markdown.Convert( mdFile, TXTextControl.BinaryStreamType.WordprocessingML);
The converted results of the following sample Markdown file can be seen in the screenshot below:
---
__Advertisement__
- __[pica](https://nodeca.github.io/pica/demo/)__ - high quality and fast image
resize in browser.
- __[babelfish](https://github.com/nodeca/babelfish/)__ - developer friendly
i18n with plurals support and easy syntax.
You will like those projects!
---
# h1 Heading
## h2 Heading
### h3 Heading
#### h4 Heading
##### h5 Heading
###### h6 Heading
## Horizontal Rules
___
---
***
## Emphasis
**This is bold text**
__This is bold text__
*This is italic text*
_This is italic text_
~~Strikethrough~~
## Blockquotes
> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.
## Lists
Unordered
+ Create a list by starting a line with `+`, `-`, or `*`
+ Sub-lists are made by indenting 2 spaces:
- Marker character change forces new list start:
* Ac tristique libero volutpat at
+ Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
+ Very easy!
Ordered
1. Lorem ipsum dolor sit amet
2. Consectetur adipiscing elit
3. Integer molestie lorem at massa
1. You can use sequential numbers...
1. ...or keep all the numbers as `1.`
Start numbering with offset:
57. foo
1. bar
## Tables
| Option | Description |
| ------ | ----------- |
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |
Right aligned columns
| Option | Description |
| ------:| -----------:|
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |

ASP.NET
Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.
- Angular
- Blazor
- React
- JavaScript
- ASP.NET MVC, ASP.NET Core, and WebForms
Related Posts
Sneak Peek: TX Text Control 34.0 Coming November 2025
We are excited to announce the upcoming release of TX Text Control 34.0, scheduled for November 2025. This update brings a host of new features and improvements to enhance your document processing…
TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version
TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…
TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version
TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…
Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format
Maintaining the integrity and functionality of documents throughout their lifecycle is paramount. TX Text Control provides a robust ecosystem that focuses on preserving documents in their internal…
Expert Implementation Services for Legacy System Modernization
We are happy to officially announce our partnership with Quality Bytes, a specialized integration company with extensive experience in modernizing legacy systems with TX Text Control technologies.