DocWright 1.1.4
dotnet add package DocWright --version 1.1.4
NuGet\Install-Package DocWright -Version 1.1.4
<PackageReference Include="DocWright" Version="1.1.4" />
<PackageVersion Include="DocWright" Version="1.1.4" />
<PackageReference Include="DocWright" />
paket add DocWright --version 1.1.4
#r "nuget: DocWright, 1.1.4"
#:package DocWright@1.1.4
#addin nuget:?package=DocWright&version=1.1.4
#tool nuget:?package=DocWright&version=1.1.4
DocWright
Word documents in .NET, rendered the way Word renders them. Convert DOCX and DOC to PDF and images, edit and generate documents, run mail merges, compare versions and run SSRS reports, all in managed code, with no Microsoft Word, no Office interop and no native binaries.
๐ Documentation ยท Get started ยท Tutorials ยท Guides ยท API reference
Features
- Convert to PDF that matches Word's own export. Layout is measured against Word, document by document, with PDF/A-2b archival output and tagged, accessible PDF.
- Render page images: PNG or JPEG at any resolution or size, for Word documents and for existing PDF files.
- Edit documents: find and replace across formatting runs, fill
{{placeholder}}templates, bookmarks and ranges, fields, forms and content controls, merge and split documents. - Assemble PDFs: merge, split, extract, delete and reorder pages of existing PDFs, without re-rendering them.
- Open protected files: password-protected DOCX and DOC, with AES-256 encryption on save.
- Handle untrusted input safely: resource limits against ZIP bombs, oversized images, deep nesting and slow documents. Nothing is fetched and nothing is executed.
- Get the same bytes every time: identical input and options produce byte-identical output on every framework and platform. One converter is safe to share across threads.
- Add capabilities as you need them: mail merge, fluent document composition, document comparison, digital signatures, complex-script shaping and SSRS reporting ship as separate packages.
| Format | Read | Write |
|---|---|---|
| DOCX | โ | โ |
| DOC (Word 97โ2003) | โ | |
| pages to images | โ (incl. PDF/A-2b) | |
| PNG, JPEG | โ | |
| HTML, RTF, Markdown, plain text | โ | โ |
| ODT, EPUB 3, SSRS RDL/RDLC | โ |
Install
dotnet add package DocWright
That is all you need for everything on this page โ the format readers, writers, layout engine, font engine and both renderers come with it automatically.
Convert a document to PDF
using DocWright;
var converter = new DocWrightConverter();
using FileStream input = File.OpenRead("report.docx");
using FileStream output = File.Create("report.pdf");
ConversionResult result = converter.Convert(input, output);
Console.WriteLine($"{result.PageCount} pages");
Convert always renders to PDF. The input format is detected automatically; override that
with ConvertOptions.SourceFormat when you are reading from a stream with no file name.
Your first conversion โ
Save to another document format
Converting renders to PDF; saving round-trips an editable format, chosen by extension:
using DocWright;
var converter = new DocWrightConverter();
using var document = converter.Load(File.OpenRead("report.docx"));
using FileStream html = File.Create("report.html");
converter.Save(document, html, ".html");
Writers ship for .docx, .html, .md, .rtf, .txt, .odt, .epub, .rdl and .rdlc.
Readers ship for .docx, .doc, .html, .md, .rtf and .txt.
Formats โ
Convert a document to images
using DocWright;
using DocWright.Renderers.Imaging;
var converter = new DocWrightConverter();
var imageOptions = new ImageRenderOptions
{
Dpi = 150,
Format = ImageOutputFormat.Png,
PageEncoded = (pageNumber, bytes) => File.WriteAllBytes($"page-{pageNumber}.png", bytes),
};
using FileStream input = File.OpenRead("report.docx");
converter.ConvertToImages(input, imageOptions);
Rasterize an existing PDF
using DocWright;
using DocWright.Renderers.Imaging;
var converter = new DocWrightConverter();
var imageOptions = new ImageRenderOptions
{
Dpi = 150,
Format = ImageOutputFormat.Png,
PageEncoded = (pageNumber, bytes) => File.WriteAllBytes($"page-{pageNumber}.png", bytes),
};
using FileStream input = File.OpenRead("statement.pdf");
converter.ConvertPdfToImages(input, imageOptions);
ConvertToImages and ConvertPdfToImages have no output stream of their own, so
ImageRenderOptions must set either PageEncoded or PageStreamFactory to receive the
pages; they throw if neither is set.
PDF is not a document importer, so Load will not accept a PDF โ use ConvertPdfToImages
for page images, or PdfPages / PdfPageAssembly (namespace DocWright.Formats.Pdf) to
delete, extract, reorder, merge or split the pages of existing PDFs without rasterizing them.
Assemble PDFs โ
Load, edit and save
using DocWright;
using DocWright.Dom;
using DocWright.Dom.Editing;
var converter = new DocWrightConverter();
using WordDocument document = converter.Load(File.OpenRead("template.docx"));
document.ReplacePlaceholders(new Dictionary<string, object?>
{
["CustomerName"] = "Contoso Ltd.",
["InvoiceTotal"] = 1499.00m,
});
using FileStream output = File.Create("filled.docx");
converter.Save(document, output);
Find and replace, {{placeholder}} template filling, bookmarks and ranges, merge and
split, content controls, legacy form fields and custom-XML binding are all included here.
Editing guides โ
Performance
DocWrightConverter caches its font engine per instance, and building one costs about a
second. Create one converter and reuse it โ a converter per document turns a
ten-second batch into a very long one. It is safe to use concurrently.
// Do this once, at startup, and share it.
static readonly DocWrightConverter Converter = new DocWrightConverter();
Optional add-ons
Everything above ships in this package. These are separate installs, added only when you want them:
| Package | Adds |
|---|---|
DocWright.Composition |
Build a document from code with a fluent, declarative API |
DocWright.MailMerge |
Merge fields, repeating regions, conditional records |
DocWright.Compare |
Diff two documents into one with tracked changes |
DocWright.Signatures |
Verify and create package and PDF signatures |
DocWright.ComplexText |
HarfBuzz shaping for complex scripts beyond the built-in Arabic and Hebrew shaping (Indic and others) |
DocWright.Reporting |
Run SSRS / Power BI paginated reports (.rdl) against your own data |
DocWright.Cryptography and DocWright.Ole come with this package as dependencies:
password-protected documents open through ConvertOptions.Password and save encrypted
through SaveOptions.Encryption.
Which packages do I need? โ
Documentation
| Get started | Install, first conversion, async, error handling |
| Tutorials | A conversion web API, mail-merge invoices, JSON templates, reports in code, comparing contracts, assembling PDFs, SSRS reports |
| Guides | Conversion options, fonts, PDF/A, editing, formats, reporting, security |
| API reference | Every public type and member |
Every code example in the documentation is compiled and run, and its output shown.
Requirements
.NET Framework 4.8, .NET Standard 2.0, .NET 8.0 or .NET 10.0. Conversion is stateless and concurrency-safe, and honours cancellation and configurable resource limits.
Support and contact
Questions, feedback, support or licensing enquiries:
- โ๏ธ Email: salwan@albahadly.com
- ๐ Website: www.albahadly.com
- ๐ Documentation: docs.albahadly.com/docwright
License
MIT. See LICENSE and THIRD-PARTY-NOTICES.md in the package.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.8
- DocWright.Core (>= 1.1.4)
- DocWright.Cryptography (>= 1.1.4)
- DocWright.Dom (>= 1.1.4)
- DocWright.Fonts (>= 1.1.4)
- DocWright.Formats.Doc (>= 1.1.4)
- DocWright.Formats.Docx (>= 1.1.4)
- DocWright.Formats.Epub (>= 1.1.4)
- DocWright.Formats.Html (>= 1.1.4)
- DocWright.Formats.Markdown (>= 1.1.4)
- DocWright.Formats.Odt (>= 1.1.4)
- DocWright.Formats.Pdf (>= 1.1.4)
- DocWright.Formats.Rdl (>= 1.1.4)
- DocWright.Formats.Rtf (>= 1.1.4)
- DocWright.Formats.Text (>= 1.1.4)
- DocWright.Layout (>= 1.1.4)
- DocWright.Renderers.Imaging (>= 1.1.4)
- DocWright.Renderers.Pdf (>= 1.1.4)
- Microsoft.Bcl.HashCode (>= 1.1.1)
- System.Buffers (>= 4.6.1)
- System.Memory (>= 4.6.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
.NETStandard 2.0
- DocWright.Core (>= 1.1.4)
- DocWright.Cryptography (>= 1.1.4)
- DocWright.Dom (>= 1.1.4)
- DocWright.Fonts (>= 1.1.4)
- DocWright.Formats.Doc (>= 1.1.4)
- DocWright.Formats.Docx (>= 1.1.4)
- DocWright.Formats.Epub (>= 1.1.4)
- DocWright.Formats.Html (>= 1.1.4)
- DocWright.Formats.Markdown (>= 1.1.4)
- DocWright.Formats.Odt (>= 1.1.4)
- DocWright.Formats.Pdf (>= 1.1.4)
- DocWright.Formats.Rdl (>= 1.1.4)
- DocWright.Formats.Rtf (>= 1.1.4)
- DocWright.Formats.Text (>= 1.1.4)
- DocWright.Layout (>= 1.1.4)
- DocWright.Renderers.Imaging (>= 1.1.4)
- DocWright.Renderers.Pdf (>= 1.1.4)
- Microsoft.Bcl.HashCode (>= 1.1.1)
- System.Buffers (>= 4.6.1)
- System.Memory (>= 4.6.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
net10.0
- DocWright.Core (>= 1.1.4)
- DocWright.Cryptography (>= 1.1.4)
- DocWright.Dom (>= 1.1.4)
- DocWright.Fonts (>= 1.1.4)
- DocWright.Formats.Doc (>= 1.1.4)
- DocWright.Formats.Docx (>= 1.1.4)
- DocWright.Formats.Epub (>= 1.1.4)
- DocWright.Formats.Html (>= 1.1.4)
- DocWright.Formats.Markdown (>= 1.1.4)
- DocWright.Formats.Odt (>= 1.1.4)
- DocWright.Formats.Pdf (>= 1.1.4)
- DocWright.Formats.Rdl (>= 1.1.4)
- DocWright.Formats.Rtf (>= 1.1.4)
- DocWright.Formats.Text (>= 1.1.4)
- DocWright.Layout (>= 1.1.4)
- DocWright.Renderers.Imaging (>= 1.1.4)
- DocWright.Renderers.Pdf (>= 1.1.4)
-
net8.0
- DocWright.Core (>= 1.1.4)
- DocWright.Cryptography (>= 1.1.4)
- DocWright.Dom (>= 1.1.4)
- DocWright.Fonts (>= 1.1.4)
- DocWright.Formats.Doc (>= 1.1.4)
- DocWright.Formats.Docx (>= 1.1.4)
- DocWright.Formats.Epub (>= 1.1.4)
- DocWright.Formats.Html (>= 1.1.4)
- DocWright.Formats.Markdown (>= 1.1.4)
- DocWright.Formats.Odt (>= 1.1.4)
- DocWright.Formats.Pdf (>= 1.1.4)
- DocWright.Formats.Rdl (>= 1.1.4)
- DocWright.Formats.Rtf (>= 1.1.4)
- DocWright.Formats.Text (>= 1.1.4)
- DocWright.Layout (>= 1.1.4)
- DocWright.Renderers.Imaging (>= 1.1.4)
- DocWright.Renderers.Pdf (>= 1.1.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DocWright:
| Package | Downloads |
|---|---|
|
DocWright.Composition
Build a document from code with a fluent, declarative API for DocWright โ pages, headers and footers, columns, tables and text styling โ then render it to PDF, images or .docx through the same pipeline as a loaded document. A composition is ordinary C#, so loops, conditionals and your own data just work. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Guides, tutorials and API reference: https://docs.albahadly.com/docwright/