Rendral

Stack · .NET

Generate PDFs in .NET

The .NET PDF landscape is mostly commercial libraries with per-developer or per-server licences, or PuppeteerSharp — which downloads and runs a Chromium build on every machine that renders, including your IIS hosts and build agents.

If your document already exists as a Razor view, the simplest path is to render it to a string and POST it. One typed HttpClient, no licence to track, and no browser installed beside your app.

01Call it from .NET

render.ts
// PdfService.cs
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

public class PdfService(HttpClient http)
{
    public async Task<byte[]> RenderAsync(string html, CancellationToken ct = default)
    {
        var payload = JsonSerializer.Serialize(new
        {
            html,
            options = new { format = "A4", pageNumbers = true }
        });

        using var request = new HttpRequestMessage(
            HttpMethod.Post, "https://rendral.com/api/v1/pdf")
        {
            Content = new StringContent(payload, Encoding.UTF8, "application/json")
        };

        request.Headers.Authorization = new AuthenticationHeaderValue(
            "Bearer", Environment.GetEnvironmentVariable("RENDRAL_API_KEY"));

        using var response = await http.SendAsync(request, ct);
        response.EnsureSuccessStatusCode();

        return await response.Content.ReadAsByteArrayAsync(ct);
    }
}

Frequently asked

How do I render a Razor view to a string?

Use IRazorViewEngine with a StringWriter, or the RazorViewToStringRenderer pattern from the ASP.NET docs. Pass the resulting HTML straight to the API.

Is there a licence to worry about?

No. Commercial .NET PDF libraries typically license per developer or per deployed server; this is a metered API call with no per-seat terms.

What about PuppeteerSharp?

PuppeteerSharp works well, but it downloads and runs Chromium on every machine that renders. That install, its memory, and its patch cadence are what this removes.

Does it work with Azure App Service?

Yes, and it's a good fit — App Service sandboxes make running a local browser awkward, while an outbound HTTPS call is unrestricted.

Related

Start rendering in minutes.

A free tier, five endpoints, and SDKs for Node and Python.