Ana içeriğe geç
Bu sayfa henüz Türkçeye çevrilmedi; İngilizce sürümü gösteriliyor.
Versiyon: 0.1

.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:

MethodOperation
HtmlToPdfAsyncHTML to PDF
TemplateToPdfAsync, TemplatePreviewAsynctemplate + data to PDF / HTML
ImagesToPdfAsyncimages to PDF
MergeAsync, SplitAsyncmerge, split
SelectPagesAsync, DeletePagesAsync, RotatePagesAsyncpage operations
WatermarkAsync, StampAsyncwatermark, stamp
CompressAsynccompress
ToPdfAAsyncPDF/A-2b
EncryptAsync, DecryptAsyncpasswords
SetMetadataAsyncdocument information
GetInfoAsync, GetTextAsyncinfo, text
RenderAsyncpages to images
StartJobAsync, GetJobAsync, WaitForJobAsyncbackground jobs
IsReadyAsyncreadiness 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