Skip to main content

Quick Start for Java

Java

Java supports wkhtmltopdf integration, but Puppeteer requires additional workarounds due to its lack of native support. PDFBolt's PDF generation API offers a faster and more reliable approach to generating PDFs from HTML, URLs, and dynamic templates. Follow these steps to get started with Java.

1. Get Your API Key

  • Your API Key is available in the Admin Dashboard under the API Keys section after registration.
  • Ensure you keep this key secure, as it is required for authorization requests to the PDFBolt API.

2. Make Your First Request

Use the following examples to quickly make requests to the PDFBolt API and generate your PDF documents.

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:

import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;

public class PDFBoltIntegrationUrl {
public static void main(String[] args) throws Exception {
String jsonBody = """
{
"url": "https://example.com",
"format": "A4",
"printBackground": true
}
""";

var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.pdfbolt.com/v1/direct"))
.header("API-KEY", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
.build();

var response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());

if (response.statusCode() == 200) {
Files.write(Paths.get("webpage.pdf"), response.body());
System.out.println("PDF generated successfully");
} else {
System.err.println("HTTP " + response.statusCode());
System.err.println("Error Message: " + new String(response.body()));
}
}
}

3. What's next?

Unlock the full potential of PDFBolt by exploring its powerful features and customization options. Start with the API Endpoints and delve into the Conversion Parameters to tailor your integration to your needs.