Skip to main content

C# .NET PDF Generation API Quick Start

C#

Use the PDFBolt REST API to generate PDFs from URLs, HTML, or published templates in C#. Follow the steps below to send your first PDF generation request.

1. Get Your API Key​

Copy a conversion API key from API Credentials in your Dashboard. Use it to replace the API key placeholder in the examples below.

If you don’t have an account, sign up. The Free plan includes 50 document conversions per month. No credit card is required.

2. Make Your First Request​

The examples use .NET’s built-in HttpClient and System.Text.Json. No additional packages are required.

For your first request, select Direct to generate a PDF and save it locally.

Choose your endpoint:

The Direct endpoint returns the generated PDF in the HTTP response. The examples below save it to a local file.

Choose your source:

Convert a web page to PDF:

using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

public class DirectUrl {
public static async Task Main(string[] args) {
using var client = new HttpClient();

var requestData = new {
url = "https://example.com",
format = "A4",
printBackground = true
};

var request = new HttpRequestMessage {
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.pdfbolt.com/v1/direct"),
Content = new StringContent(
JsonSerializer.Serialize(requestData),
Encoding.UTF8,
"application/json"
)
};

request.Headers.Add("API-KEY", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");

try {
using var response = await client.SendAsync(request);

if (!response.IsSuccessStatusCode) {
var errorContent = await response.Content.ReadAsStringAsync();
Console.WriteLine($"HTTP {(int)response.StatusCode}");
Console.WriteLine($"Error Message: {errorContent}");
return;
}

var pdfBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("webpage.pdf", pdfBytes);
Console.WriteLine("PDF generated successfully");
} catch (Exception ex) {
Console.WriteLine($"Error: {ex.Message}");
}
}
}

Next Steps​