PdfBroker.io makes it easy to generate professional PDF documents from HTML templates using a simple REST API. Whether you're creating invoices, reports, or certificates, our API handles the heavy lifting so you can focus on your application logic.
Why Use a PDF Generation API?
Generating PDFs programmatically can be challenging. Browser rendering engines behave differently, font handling is complex, and maintaining a PDF generation service requires ongoing effort. PdfBroker.io solves these problems by providing a reliable, cloud-hosted API that converts your HTML and CSS into pixel-perfect PDFs.
Key Benefits
- Simple REST API — Send HTML, receive PDF
- Consistent rendering — Same output every time
- No infrastructure — No servers to maintain
- Fast generation — Optimized for speed
Authentication
PdfBroker.io uses OAuth2 Client Credentials authentication. See the full Authentication documentation for details. You'll find your Client ID and Client Secret in the Members API Credentials page after signing up.
To call the API, you first exchange your client credentials for an access token:
curl -X POST https://login.pdfbroker.io/connect/token \
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
The response contains an access_token that you include as a Bearer token in all API requests. The PdfBroker.Client NuGet package handles this automatically.
Quick Start
Using cURL
The fastest way to test the API. First get an access token, then generate a PDF:
# Step 1: Get an access token
ACCESS_TOKEN=$(curl -s -X POST https://login.pdfbroker.io/connect/token \
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" \
| jq -r '.access_token')
# Step 2: Generate a PDF from a URL
curl -X POST https://api.pdfbroker.io/api/pdf/wkhtmltopdf \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"url": "https://www.example.com",
"wkHtmlToPdfArguments": {
"page-size": "A4",
"margin-top": "10mm",
"margin-bottom": "10mm"
}
}' \
--output document.pdf
Or generate a PDF from an HTML string (base64 encoded):
curl -X POST https://api.pdfbroker.io/api/pdf/wkhtmltopdf \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"htmlBase64String": "PGh0bWw+PGJvZHk+PGgxPkhlbGxvIGZyb20gUGRmQnJva2VyLmlvPC9oMT48cD5HZW5lcmF0ZWQgd2l0aCB0aGUgUERGIEFQSS48L3A+PC9ib2R5PjwvaHRtbD4=",
"wkHtmlToPdfArguments": { "page-size": "A4" }
}' \
--output document.pdf
Using C# with PdfBroker.Client
For .NET developers, our PdfBroker.Client NuGet package handles authentication and API calls automatically. See the .NET Client Library documentation for the full API reference.
dotnet add package PdfBroker.Client
Generate a PDF from a URL:
using PdfBroker.Client;
using PdfBroker.Common.RequestObjects;
// Client authenticates automatically using OAuth2 client credentials
var client = new PdfBrokerClientService("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
var request = new WkHtmlToPdfRequestDto
{
Url = "https://www.example.com",
WkHtmlToPdfArguments = new Dictionary<string, string>
{
{ "page-size", "A4" },
{ "margin-top", "10mm" },
{ "margin-bottom", "10mm" }
}
};
byte[] pdfBytes = await client.WkHtmlToPdfAsByteArrayAsync(request);
File.WriteAllBytes("document.pdf", pdfBytes);
Or generate a PDF from an HTML string:
using PdfBroker.Client;
using PdfBroker.Common.RequestObjects;
var client = new PdfBrokerClientService("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
var html = @"<html>
<head><style>body { font-family: sans-serif; } h1 { color: #6462a8; }</style></head>
<body>
<h1>Invoice #1234</h1>
<p>Total: €99.00</p>
</body></html>";
var request = new WkHtmlToPdfRequestDto
{
HtmlBase64String = Convert.ToBase64String(
System.Text.Encoding.UTF8.GetBytes(html)),
WkHtmlToPdfArguments = new Dictionary<string, string>
{
{ "page-size", "A4" }
}
};
byte[] pdfBytes = await client.WkHtmlToPdfAsByteArrayAsync(request);
File.WriteAllBytes("invoice.pdf", pdfBytes);
Using C# with HttpClient (without NuGet package)
If you prefer not to use the NuGet package, you can call the API directly:
using System.Net.Http.Headers;
// Step 1: Get an access token
using var tokenClient = new HttpClient();
var tokenResponse = await tokenClient.PostAsync(
"https://login.pdfbroker.io/connect/token",
new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "client_credentials",
["client_id"] = "YOUR_CLIENT_ID",
["client_secret"] = "YOUR_CLIENT_SECRET"
}));
var tokenJson = await tokenResponse.Content.ReadAsStringAsync();
var accessToken = JsonDocument.Parse(tokenJson)
.RootElement.GetProperty("access_token").GetString();
// Step 2: Call the PDF API
using var apiClient = new HttpClient();
apiClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", accessToken);
var response = await apiClient.PostAsJsonAsync(
"https://api.pdfbroker.io/api/pdf/wkhtmltopdf",
new
{
url = "https://www.example.com",
wkHtmlToPdfArguments = new Dictionary<string, string>
{
{ "page-size", "A4" }
}
});
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("document.pdf", pdfBytes);
What's Next?
Now that you've seen the basics, explore these resources:
- Getting Started Guide — Step-by-step setup and first API call
- WeasyPrint HTML to PDF — Modern HTML/CSS to PDF with WeasyPrint
- .NET Client Library — Full NuGet package reference
- Authentication — OAuth2 credentials and token management
- Pricing — Choose the plan that fits your needs
Happy PDF generating!