DocxWorkshop Server ยท 0.1.0

Server SDK quickstart

Generate and convert Word documents from a .NET 10 console app or background job. The SDK runs the DocxWorkshop document engine in headless Chromium on the server.

Try a background conversion in the trial with an activated DocxWorkshop trial code.

Install the NuGet package and Chromium

Use the .NET 10 SDK and the standard .NET runtime with reflection-based JSON serialization enabled for Playwright. Create a console project.

Create a console project
dotnet new console -n DocxWorkshopWorker -f net10.0 --no-restore
Set-Location DocxWorkshopWorker
New-Item -ItemType Directory -Path packages

Put DocxWorkshop.Server.0.1.0.nupkg in packages. Create this NuGet.Config file beside your project so restore can find the local package and its Playwright dependency.

NuGet.Config
<configuration>
  <packageSources>
    <clear />
    <add key="DocxWorkshop local" value="./packages" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>
Restore and install Chromium
dotnet add package DocxWorkshop.Server --version 0.1.0 --no-restore
dotnet restore --configfile ./NuGet.Config
dotnet build --no-restore
pwsh -File ./bin/Debug/net10.0/playwright.ps1 install chromium --only-shell

To use Microsoft Edge or Google Chrome already installed on the machine, pass "msedge" or "chrome" to StartAsync.

Generate a DOCX and export a searchable PDF

This example creates a Word template in memory, replaces a customer placeholder, and exports the result to PDF. Replace Program.cs with the following.

Program.cs
using DocxWorkshop.Server;

await using var processor = await DocxWorkshopDocumentProcessor.StartAsync();
await using var template = new MemoryStream();
await processor.CreateDocumentAsync("Invoice", "Customer: {{Customer}}",
    template, DocxWorkshopOutputFormat.Docx);

template.Position = 0;
await using var pdf = File.Create("invoice.pdf");
var result = await processor.ConvertAsync(template, pdf, DocxWorkshopOutputFormat.Pdf,
    new Dictionary<string, string> { ["{{Customer}}"] = "Acme" });

Console.WriteLine($"Replaced {result.Replacements} occurrence(s).");
Run the console app
dotnet run --no-restore

Open invoice.pdf and search for Acme. To process your own template, use File.OpenRead("template.docx") for the input stream. Choose DocxWorkshopOutputFormat.Docx and a .docx filename to save an editable Word copy.

API reference

DocxWorkshopDocumentProcessor.StartAsync()
Start the headless engine. Reuse the processor across jobs and dispose it when the application shuts down.
CreateDocumentAsync(title, text, destination, format)
Generate DOCX or PDF from a title and plain-text paragraphs.
ConvertAsync(source, destination, format, replacements)
Read DOCX from a stream, optionally replace text, and write to a separate destination stream. The result reports the number of replacements.

Conversion accepts DOCX input up to 64 MiB. Replacement terms match literal, case-sensitive text within the main document story. Use terms within a paragraph. The caller owns both streams.

To control a document the user has open in Blazor, see Edit the open document from C#.