SimplyWorks.PdfTemplarClient 8.0.0

dotnet add package SimplyWorks.PdfTemplarClient --version 8.0.0
                    
NuGet\Install-Package SimplyWorks.PdfTemplarClient -Version 8.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SimplyWorks.PdfTemplarClient" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SimplyWorks.PdfTemplarClient" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SimplyWorks.PdfTemplarClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SimplyWorks.PdfTemplarClient --version 8.0.0
                    
#r "nuget: SimplyWorks.PdfTemplarClient, 8.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SimplyWorks.PdfTemplarClient@8.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SimplyWorks.PdfTemplarClient&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SimplyWorks.PdfTemplarClient&version=8.0.0
                    
Install as a Cake Tool

PdfTemplar Client SDK

Build and Publish NuGet Package NuGet License: MIT

A .NET client SDK for PdfTemplar - a service that generates PDF documents from templates and data objects.

Features

  • Generate PDF documents by sending templates and data objects to PdfTemplar service
  • Configurable JSON naming strategies (SnakeCase, CamelCase, CapitalCase)
  • Comprehensive error handling with specific error codes
  • Built-in HTTP client integration with IHttpClientFactory
  • .NET 8.0 target framework

Installation

Install via NuGet Package Manager:

dotnet add package SimplyWorks.PdfTemplarClient

Or via Package Manager Console:

Install-Package SimplyWorks.PdfTemplarClient

Usage

Basic Setup

using Microsoft.Extensions.DependencyInjection;
using SW.PdfTemplar.Client;

// Configure services
services.AddHttpClient();

// Configure PdfTemplar settings
var settings = new PdfTemplarClientSettings
{
    ServiceUri = "https://pdftemplar.sf9.io/", // Default service URI
    NamingStrategy = NamingStrategy.CamelCase   // JSON naming strategy
};

// Create client instance
var pdfTemplar = new PdfTemplar(settings, httpClientFactory);

Generate PDF Document

// Define your data model
var model = new
{
    CustomerName = "John Doe",
    OrderDate = DateTime.Now,
    Items = new[]
    {
        new { Product = "Widget A", Quantity = 2, Price = 10.00 },
        new { Product = "Widget B", Quantity = 1, Price = 15.00 }
    }
};

try
{
    // Generate PDF document
    FileData pdfFile = await pdfTemplar.GetDocument("invoice-template", model);
    
    // Use the generated PDF
    string fileName = pdfFile.FileName;        // "generatedPDF.pdf"
    string mimeType = pdfFile.MimeType;        // "application/pdf"
    byte[] pdfContent = pdfFile.InlineData;    // PDF file bytes
}
catch (PdfTemplarException ex)
{
    // Handle specific PDF generation errors
    switch (ex.Error)
    {
        case PdfTemplarError.TemplateInvalid:
            // Handle invalid template
            break;
        case PdfTemplarError.ServerError:
            // Handle server error
            break;
        case PdfTemplarError.Timeout:
            // Handle timeout
            break;
        case PdfTemplarError.GatewayError:
            // Handle gateway error
            break;
    }
}

Configuration

PdfTemplarClientSettings

Property Type Default Description
ServiceUri string "https://pdftemplar.sf9.io/" The base URI of the PdfTemplar service
NamingStrategy NamingStrategy CapitalCase JSON serialization naming strategy

Naming Strategies

  • CapitalCase - PascalCase property names (default)
  • CamelCase - camelCase property names
  • SnakeCase - snake_case property names

Error Handling

The SDK provides specific error codes through PdfTemplarException:

Error Code Description
TemplateInvalid The provided template is invalid or not found
ServerError Internal server error occurred
Timeout Request timed out
GatewayError Gateway error (service may be restarting)

Models

FileData

Represents the generated PDF document:

public class FileData
{
    public string MimeType { get; set; }    // "application/pdf"
    public byte[] InlineData { get; set; }  // PDF file content
    public string FileName { get; set; }    // File name
}

Dependencies

  • Microsoft.Extensions.Http (8.0.1) - HTTP client factory
  • Newtonsoft.Json (13.0.4) - JSON serialization
  • System.Configuration.ConfigurationManager (8.0.1) - Configuration management
  • System.Text.Encoding (4.3.0) - Text encoding support

Requirements

  • .NET 8.0 or later
  • Access to PdfTemplar service

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

This is an open source project by Simplify9. Contributions are welcome!

Support

For issues and questions, please use the GitHub Issues page.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.0.0 348 9/16/2025
2.0.3 2,737 8/30/2022