# 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.

> **Note:** This article is outdated and may no longer be accurate.

- **Author:** Bjoern Meyer
- **Published:** 2022-11-15
- **Modified:** 2026-07-17
- **Description:** 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.
- **4 min read** (697 words)
- **Tags:**
  - ASP.NET
  - Markdown
  - Windows Forms
  - WPF
- **Web URL:** https://www.textcontrol.com/blog/2022/11/15/converting-markdown-to-docx-and-pdf-in-csharp/
- **LLMs URL:** https://www.textcontrol.com/blog/2022/11/15/converting-markdown-to-docx-and-pdf-in-csharp/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2022/11/15/converting-markdown-to-docx-and-pdf-in-csharp/llms-full.txt

---

> **⚠️ 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 ](https://www.textcontrol.com/blog/2025/09/16/introducing-txtextcontrol-markdown-core-import-and-export-markdown-in-tx-text-control/llms-full.txt)

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](https://github.com/xoofx/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](https://www.textcontrol.com/product/tx-text-control-dotnet-server/download/)  
>     Setup download and installation required.

##### Creating the Application

1. In Visual Studio, create a new *Console App*.  
    ![Markdown to DOCX](https://s1-www.textcontrol.com/assets/dist/blog/2022/11/15/a/assets/markdown1.webp "Markdown to DOCX")
2. 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*.  
    ![Markdown to DOCX](https://s1-www.textcontrol.com/assets/dist/blog/2022/11/15/a/assets/markdown2.webp "Markdown to DOCX")
3. Switch the *Package source* to *Text Control Offline Packages* and install the package *TXTextControl.TextControl.ASP.SDK*.  
    ![Markdown to DOCX](https://s1-www.textcontrol.com/assets/dist/blog/2022/11/15/a/assets/markdown3.webp "Markdown to DOCX")
4. 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;
             }
          }
       }
    }
    ```
5. 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. |
```

![Markdown to DOCX](https://s1-www.textcontrol.com/assets/dist/blog/2022/11/15/a/assets/markdown4.webp "Markdown to DOCX")

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [TXTextControl.Markdown.Core 34.1.0-beta: Work with Full Documents, Selection, and SubTextParts](https://www.textcontrol.com/blog/2026/04/14/txtextcontrol-markdown-core-34-1-0-beta-work-with-full-documents-selection-and-subtextparts/llms.txt)
- [TX Text Control 34.0 SP4 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/05/20/tx-text-control-34-0-sp4-is-now-available/llms.txt)
- [TX Spell .NET 11.0 SP1 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/04/08/tx-spell-net-11-0-sp1-is-now-available/llms.txt)
- [TX Text Control 34.0 SP2 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/02/18/tx-text-control-34-0-sp2-is-now-available/llms.txt)
- [TX Text Control 34.0 SP1 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2025/12/03/tx-text-control-34-0-sp1-is-now-available/llms.txt)
- [Introducing TX Text Control 34.0: Your Next Leap in Document Processing](https://www.textcontrol.com/blog/2025/11/10/introducing-tx-text-control-34-0-your-next-leap-in-document-processing/llms.txt)
- [Sneak Peek: TX Text Control 34.0 Coming November 2025](https://www.textcontrol.com/blog/2025/10/02/sneak-peek-tx-text-control-34-0-coming-november-2025/llms.txt)
- [TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2025/08/14/tx-text-control-33-0-sp3-is-now-available/llms.txt)
- [TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2025/06/18/tx-text-control-33-0-sp2-is-now-available/llms.txt)
- [Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format](https://www.textcontrol.com/blog/2025/05/16/document-lifecycle-optimization-leveraging-tx-text-controls-internal-format/llms.txt)
- [Expert Implementation Services for Legacy System Modernization](https://www.textcontrol.com/blog/2025/05/07/expert-implementation-services-for-legacy-system-modernization/llms.txt)
- [Service Pack Releases: What's New in TX Text Control 33.0 SP1 and 32.0 SP5](https://www.textcontrol.com/blog/2025/05/07/service-pack-releases-whats-new-in-tx-text-control-33-0-sp1-and-32-0-sp5/llms.txt)
- [Top 5 Real-World Applications for TX Text Control Document Processing Libraries](https://www.textcontrol.com/blog/2025/04/01/top-5-real-world-applications-for-tx-text-control-document-processing-libraries/llms.txt)
- [DWX Developer Week Moves to Mannheim - And Text Control Is on Board!](https://www.textcontrol.com/blog/2025/03/19/dwx-developer-week-moves-to-mannheim-and-tx-text-control-is-on-board/llms.txt)
- [The Wait is Over: TX Text Control for Linux is Officially Here](https://www.textcontrol.com/blog/2025/03/12/the-wait-is-over-tx-text-control-for-linux-is-officially-here/llms.txt)
- [Full .NET 9 Support in Text Control .NET Components for ASP.NET Core, Windows Forms, and WPF](https://www.textcontrol.com/blog/2024/11/11/full-net-9-support-in-text-control-net-components-for-asp-net-core-windows-forms-and-wpf/llms.txt)
- [Toggle Field Codes in TX Text Control](https://www.textcontrol.com/blog/2024/11/07/toggle-field-codes-in-tx-text-control/llms.txt)
- [TX Text Control 32.0 Service Pack 4 Released](https://www.textcontrol.com/blog/2024/09/02/tx-text-control-32-0-service-pack-4-released/llms.txt)
- [Service Pack 3: MailMerge Supports SVG Images](https://www.textcontrol.com/blog/2024/04/29/service-pack-3-mailmerge-supports-svg-images/llms.txt)
- [TX Text Control 32.0 Service Pack 3 Released](https://www.textcontrol.com/blog/2024/04/29/tx-text-control-32-0-service-pack-3-released/llms.txt)
- [Electronic Invoicing will Become Mandatory in Germany in 2025](https://www.textcontrol.com/blog/2024/04/10/electronic-invoicing-will-become-mandatory-in-germany-in-2025/llms.txt)
- [Inserting MergeBlocks with the DataSourceManager and Applying Table Styles in C#](https://www.textcontrol.com/blog/2024/04/09/inserting-mergeblocks-with-the-datasourcemanager-and-applying-table-styles-in-csharp/llms.txt)
- [The Power of SubTextParts: Typical Use Cases](https://www.textcontrol.com/blog/2024/02/09/the-power-of-subtextparts-typical-use-cases/llms.txt)
- [Renaming Merge Blocks and Merge Fields Programmatically in C#](https://www.textcontrol.com/blog/2024/02/08/renaming-merge-blocks-and-merge-fields-programmatically-in-csharp/llms.txt)
- [Encapsulating TX Text Control in Class Libraries](https://www.textcontrol.com/blog/2024/01/09/encapsulating-tx-text-control-in-class-libraries/llms.txt)
