DocSharp is a pure C# library to convert between document formats without Office interop or native dependencies.
The following packages are currently available:
- DocSharp.Binary: convert Office 97-2003 binary documents (doc, xls, ppt) to OpenXML documents (docx, xlsx, pptx). This is a fork of the abandoned b2xtranslator project which provides critical fixes.
- DocSharp.Docx: convert DOCX to Markdown, RTF and plain text (.txt). Possible applications include generating Open XML documents in C# and exporting for other editors, or loading Word documents in a RichTextBox / RichEditBox control.
- DocSharp.Markdown: convert Markdown to DOCX using a custom Markdig renderer.
Packages can be installed via NuGet:
The optional extra packages DocSharp.ImageSharp and DocSharp.SystemDrawing allow to convert unsupported images (e.g. GIF / TIFF for DOCX -> RTF or WMF / EMF / TIFF for DOCX -> MD).
There is no common DOM to manipulate or generate documents, this library is mainly for conversion. However, the Docx package provides some helper methods on top of the Open XML SDK that may be extended in the future.
If your main purpose is creating documents from scratch you can consider the following libraries: OfficeIMO, OpenXML-Office, ClosedXML, ShapeCrawler, QuestPDF, MigraDoc.
- Binary formats: most doc/xls/ppt features were supported by the original project, but exceptions occurred when using .NET (rather than .NET Framework) or loading specific documents. The most noticeable issues have been fixed, but more work is needed to make the library reliable; if you find other bugs, you are welcome to open an issue (please attach a sample file if the issue only occurs for specific documents).
- DOCX, RTF, Markdown: supported elements vary depending on input and output formats, see Supported features for an overview.
.NET 6, 8, 9 and .NET Framework 4.6.2 and higher are supported, but tests are mostly performed on .NET 8 and above.
You can refer to the project Wiki or sample app.
- Support more elements and attributes, and fix issues on edge cases
- Reverse RTF to DOCX conversion
- Async functions/progress callback (some tasks such as downloading images referenced in Markdown may take some time)
- Improve support for right-to-left and complex script languages
Dependencies:
- Open XML SDK
- Markdig - for DocSharp.Markdown
- ImageSharp and VectSharp - for DocSharp.ImageSharp
- System.Drawing.Common and SVG.NET - for DocSharp.SystemDrawing (supported on Windows only)
Forked:
Others:
- Html2OpenXml for images header decoding and unit conversions.
- dwml_cs for Office Math (OMML) conversion
- OpenXmlToHtml, XlsxToHtmlConverter and PeachPdf are only used in the sample app to test two-steps conversions.
DocSharp is licensed under MIT license and can be used for both open source and commercial projects.
DocSharp.ImageSharp is licensed under Apache 2.0 license; ImageSharp and VectSharp have their own licenses, please visit their repositories for more information.
If you find the library useful, adding a star is highly appreciated.