Parchment
Parchment is a Word document generation library that combines docx templates or markdown with a .NET data model via liquid templating.
Install
| Product | Versions |
|---|---|
| .NET |
README
Parchment
Parchment is a Word (.docx) generation library that combines a .NET data model with either a docx template (token replacement) or a markdown template (full content rendering), driven by liquid via Fluid, Markdig, and OpenXmlHtml.
Docx template flow
var store = new TemplateStore();
store.RegisterDocxTemplate<Invoice>("invoice", File.ReadAllBytes("invoice-template.docx"));
var bytes = await store.Render("invoice", SampleData.Invoice());
File.WriteAllBytes("out.docx", bytes);
The template may include:
- Substitution tokens:
{{ customer.name }} - Paragraph-scope loops:
{% for line in lines %}…{% endfor %} - Table-row-scope loops: put
{% for line in lines %}on its own in one row and{% endfor %}on its own in another - Conditionals:
{% if customer.is_preferred %}…{% endif %}
Markdown template flow
store.RegisterMarkdownTemplate<Report>("report", markdownSource, styleSource: brandDocxBytes);
var bytes = await store.Render("report", reportModel);
Source generator
Decorate the model class itself with [ParchmentModel] and Parchment's source generator validates the template tokens against it at compile time. Both .docx and .md templates are supported.
[ParchmentModel("Templates/invoice.docx")]
public partial class Invoice
{
public string Number { get; set; } = "";
// ...
}
[ParchmentModel("Templates/report.md")]
public partial class Report
{
public string Title { get; set; } = "";
// ...
}
See the readme for full documentation.
Changes from Previous Version
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.