.NET Client
Pidief.Client is a typed .NET client for the pidief HTTP API. It targets net8.0 and net10.0 and is published as the Pidief.Client NuGet package. The source is in clients/dotnet/src/Pidief.Client in the repository.
Registration
builder.Services.AddPidiefClient(o =>
{
o.BaseAddress = new Uri(builder.Configuration["Pidief:Url"]!);
o.ApiKey = builder.Configuration["Pidief:ApiKey"];
o.Timeout = TimeSpan.FromSeconds(60); // per attempt
o.MaxRetries = 3; // 429/502/503/504, network errors, attempt timeouts; honours Retry-After
});
Usage
Inject IPidiefClient and call the operation you need:
public sealed class ReportPdf(IPidiefClient pidief)
{
public async Task<byte[]> CreateAsync(string html, byte[] logo, CancellationToken ct)
{
var pdf = await pidief.HtmlToPdfAsync(html,
new HtmlOptions { PageNumbers = true, Title = "Monthly report", PdfA = true },
[new PidiefFile("img/logo.png", logo)], ct);
var thumbnail = await pidief.RenderAsync(new PidiefFile("report.pdf", pdf),
new RenderOptions { Pages = "1", Format = "webp", MaxWidth = 300 }, ct);
return pdf;
}
}
Available methods
IPidiefClient has one method per operation:
| Method | Operation |
|---|---|
HtmlToPdfAsync | HTML to PDF |
TemplateToPdfAsync, TemplatePreviewAsync | template + data to PDF / HTML |
ImagesToPdfAsync | images to PDF |
MergeAsync, SplitAsync | merge, split |
SelectPagesAsync, DeletePagesAsync, RotatePagesAsync | page operations |
WatermarkAsync, StampAsync | watermark, stamp |
CompressAsync | compress |
ToPdfAAsync | PDF/A-2b |
EncryptAsync, DecryptAsync | passwords |
SetMetadataAsync | document information |
GetInfoAsync, GetTextAsync | info, text |
RenderAsync | pages to images |
StartJobAsync, GetJobAsync, WaitForJobAsync | background jobs |
IsReadyAsync | readiness check |
Long-running work
Use StartJobAsync to start a background job and WaitForJobAsync to wait for its result.
Errors
Errors throw PidiefException, which exposes StatusCode, RequestId and IsInvalidRequest (true for a 400 response).
Tests
dotnet test clients/dotnet/Pidief.Client.slnx
PIDIEF_URL=http://localhost:3000/ PIDIEF_API_KEY=... dotnet test clients/dotnet/Pidief.Client.slnx # live end-to-end