Fill existing PDF templates with C# & .NET. Set up a PDF template, send data to Anvil, and get back a completed PDF — no manual entry required.
using Anvil.Client;
class FillExample
{
static async Task Main(string[] args)
{
var apiKey = Environment.GetEnvironmentVariable("ANVIL_API_KEY");
// A sample PDF template available to any account. See
// https://www.useanvil.com/help/tutorials/set-up-a-pdf-template to
// set up your own template.
var pdfTemplateEid = "05xXsZko33JIO6aq5Pnr";
var longText =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
var payload = new Anvil.Payloads.Request.FillPdf
{
Title = "My PDF Title",
FontSize = 10,
TextColor = "#333333",
// Keys here match the field IDs configured on the PDF template
Data = new Dictionary<string, dynamic>()
{
{"shortText", "Hello World!"},
{"date", "2024-01-15"},
{
"name", new Dictionary<string, object>()
{
{"firstName", "Robin"},
{"mi", "W"},
{"lastName", "Smith"}
}
},
{"email", "testy@example.com"},
{
"usAddress", new Dictionary<string, object>()
{
{"street1", "123 Main St #234"},
{"city", "San Francisco"},
{"state", "CA"},
{"zip", "94106"},
{"country", "US"}
}
},
{"ssn", "456454567"},
{"ein", "897654321"},
{"checkbox", true},
{"decimalNumber", 12345.67},
{"dollar", 123.45},
{"integer", 12345},
{"percent", 50.3},
{"longText", longText}
}
};
var client = new RestClient(apiKey);
var wasWritten = await client.FillPdf(
pdfTemplateEid, payload, "./fill-output.pdf");
Console.WriteLine(wasWritten
? "Filled PDF saved to fill-output.pdf"
: "There was an error filling the PDF");
}
}
The Anvil package is MIT-licensed and maintained in the open on GitHub.
$ dotnet add package AnvilInstall the Anvil Document SDK plugin in Claude Code and Claude will scaffold the SDK into your codebase — discovery, planning, and production-ready code.
/plugin marketplace add anvilco/anvil-plugins
/plugin install anvil-document-sdk@anvil-pluginsNo API key setup needed. The plugin connects to your Anvil account with OAuth and logs you in automatically.
Instantly fill your PDF templates with JSON data. Try an example below and see documentation when ready to fill your own.