Formats
DocWright reads Word documents and several web and text formats into one document model, and writes that model to any output format. Choose the output with a file extension.
Format support
| Format | Extensions | Read | Write | Guide |
|---|---|---|---|---|
| Word | .docx |
✅ | ✅ | Lossless round trip |
| Word 97–2003 | .doc |
✅ | — | Legacy .doc |
.pdf |
pages → images | ✅ | Convert · Read PDFs | |
| PNG, JPEG | — | ✅ | Page images | |
| HTML | .html .htm .xhtml |
✅ | ✅ | HTML |
| RTF | .rtf |
✅ | ✅ | RTF and plain text |
| Markdown | .md .markdown |
✅ | ✅ | Markdown |
| Plain text | .txt .text |
✅ | ✅ | RTF and plain text |
| OpenDocument Text | .odt |
— | ✅ | ODT and EPUB |
| EPUB 3 | .epub |
— | ✅ | ODT and EPUB |
| SSRS report template | .rdl .rdlc |
— | ✅ | Word to RDL |
| Excel | .xlsx |
— | ✅ (standalone) | Writing Excel files |
Save in any format
using DocWright;
using DocWright.Dom;
// One loaded document, every output format. The extension picks the writer.
using WordDocument document = converter.Load(File.OpenRead("letterhead.docx"));
foreach (string extension in new[] { ".docx", ".html", ".rtf", ".md", ".txt", ".odt", ".epub", ".rdl" })
{
using FileStream output = File.Create("export" + extension);
converter.Save(document, output, extension);
Console.WriteLine($"export{extension,-6} {output.Length,8:N0} bytes");
}
Output
export.docx 6,695 bytes
export.html 37,398 bytes
export.rtf 54,347 bytes
export.md 2,138 bytes
export.txt 2,069 bytes
export.odt 4,246 bytes
export.epub 2,799 bytes
export.rdl 65,867 bytes
Save picks the writer from the extension. For a writer's own options, construct it (new HtmlWriter(new HtmlWriteOptions { … })) and call Write, or pass settings through SaveOptions.FormatSettings:
using DocWright;
using DocWright.Formats.Epub;
using DocWright.Formats.Odt;
// Writer settings without constructing a writer: the format-neutral settings bag.
var epub = new SaveOptions();
epub.FormatSettings[EpubFormatSettingKeys.Title] = "Letterhead";
epub.FormatSettings[EpubFormatSettingKeys.Language] = "en";
epub.FormatSettings[EpubFormatSettingKeys.Split] = "section";
using (FileStream output = File.Create("letterhead-book.epub"))
{
converter.Save(document, output, ".epub", epub);
}
var odt = new SaveOptions();
odt.FormatSettings[OdtFormatSettingKeys.Title] = "Letterhead";
using (FileStream output = File.Create("letterhead-titled.odt"))
{
converter.Save(document, output, ".odt", odt);
}
Important
Keep the source stream open until you've saved. A loaded document reads images and large parts from its source lazily. Saving over the file you loaded from, or disposing its stream first, fails.
Conversions that go through the model
Any readable format converts to any writable one: HTML to DOCX, Markdown to PDF, DOCX to Markdown, .doc to .docx. Formats that can express less than Word (HTML, Markdown, text, RTF) lose what they can't represent, such as page setup and headers. Each guide lists the losses. The loss happens once: exporting again doesn't lose more.