Skip to main content

Quick Start for C#

C#

C# offers several PDF generation libraries like PuppeteerSharp and DinkToPdf, but they often require learning specialized APIs and have limited HTML/CSS support. PDFBolt's PDF generation API provides a straightforward HTTP-based approach for generating PDFs from HTML, URLs, and dynamic templates using familiar .NET patterns.

1. Get Your API Key

  • After signing up, locate your API Key in the Admin Dashboard under the API Keys section.
  • This key is essential for authorizing your requests to the PDFBolt API. Remember to keep it secure.

2. Make Your First Request

Use the examples below to generate PDFs with the PDFBolt API.

Choose your preferred endpoint and source combination.

➡️ Endpoints:

The Direct endpoint provides immediate PDF generation and returns the raw PDF file in the response.


➡️ Sources:

Convert any webpage into a PDF:

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

public class PDFBoltIntegrationUrl {
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),
System.Text.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}");
}
}
}

3. What's next?

Discover how PDFBolt can enhance your .NET applications. Begin with the API Endpoints and explore the Conversion Parameters to customize your setup and meet your specific needs.