A .docx someone made in Word stays the design; your code supplies the values. Placeholders take single values, loops write a passage or a table row once per item, conditional blocks keep or drop a passage, and the same service converts the result to PDF.
The interfaces below are the part that does not change when you swap the library underneath. Each provider then adds whatever extras its own library exposes.
WordTemplateInput carries the document and two dictionaries: one for single values, one for collections. {{#each Key}} … {{else}} … {{/each}} writes a passage or a set of table rows once per item, and {{#if Key}} … {{else}} … {{/if}} keeps one branch or the other. The two nest in each other.
Convert a generated document to PDF or another format through the same service — no second library for the signing copy.
Append an addendum, a set of terms or a cover page by merging several template inputs into one document.
Pull plain text or embedded images back out, for indexing or for migrating content off old documents.
Install the one that fits your runtime and licensing, and name it once at registration. Every package here is published on nuget.org.
The provider appears where the concrete class is constructed, and nowhere else. Always-current samples live in the package documentation.
// A .docx template plus values. {{#each Sites}} … {{/each}} writes its passage once per row;
// {{#if IsPaid}} … {{else}} … {{/if}} keeps the branch that holds.
IWordService word = new Regira.Office.Word.Spire.WordService();
IMemoryFile contract = await word.Create(new WordTemplateInput
{
Template = template,
GlobalParameters = new Dictionary<string, object>
{
["ClientName"] = client.Name,
["StartDate"] = start.ToString("d"),
["IsPaid"] = invoice.AmountPaid > 0
},
CollectionParameters = new Dictionary<string, ICollection<IDictionary<string, object>>>
{
["Sites"] = sites // one row per site: {{SiteName}}, {{Address}}, {{ row_number }}
}
});
// Same service converts and merges. FreeSpire writes at most 3 PDF pages and adds a notice page;
// Word.Syncfusion, Word.Aspose or Word.Gotenberg convert longer documents.
IMemoryFile pdf = await word.Convert(new WordTemplateInput { Template = contract }, FileFormat.Pdf);Create a Word document from a template, extract plain text, merge documents and convert between DOCX and PDF over HTTP.
The free tier needs no key and is rate-limited to 5 requests / 60 s. A trial or commercial key removes the limit — send it in the X-License-Key header.