To use the Gen2PDF API, you must provide a valid apiKey.
How to authenticate:
• GET request: Include apiKey as a query parameter.
• POST request: Include apiKey in the JSON body or headers (x-api-key).
				
					GET /v1/generate?url=https://example.com&apiKey=your-api-key 
				
			
		A free API key is provided by default. You can upgrade to a higher plan depending on your usage needs.
The API supports the following parameters:
| 
 Parameter  | 
 Type  | 
 Description  | 
|---|---|---|
| 
 url / html  | 
 string  | 
 URL to fetch or raw HTML content  | 
| 
 format  | 
 string  | 
 Page size: A4, Letter, or custom size  | 
| 
 width  | 
 number  | 
 Custom width in px  | 
| 
 height  | 
 number  | 
 Custom height in px  | 
| 
 landscape  | 
 boolean  | 
 true for landscape orientation  | 
| 
 scale  | 
 number  | 
 Zoom scale (0.1 – 2)  | 
| 
 marginTop, marginRight, marginBottom, marginLeft  | 
 number  | 
 Margin in pixels  | 
| 
 waitFor  | 
 number  | 
 Wait time before rendering (in seconds)  | 
| 
 media  | 
 string  | 
 Rendering mode: screen or print  | 
| 
 filename  | 
 string  | 
 Name of the output PDF  | 
| 
 callBackUrl  | 
 string  | 
 Optional: POST the PDF to this URL  | 
Gen2PDF supports web fonts and system fonts.
Recommendations:
• Use @font-face in your HTML if needed.
• Ensure fonts are hosted on HTTPS sources.
You can insert page breaks using CSS:
				
					.page-break {
  page-break-before: always;
} 
				
			
		Usage
				
					 
				
			
		The API supports custom HTML templates for headers and footers.
Example:
				
					Page  of   
				
			
		Pass as:
				
					{
  "headerTemplate": "Page  ",
  "footerTemplate": ""
} 
				
			
		Coming soon — PDF password protection and encryption options are planned for future releases.
Basic URL to PDF
				
					GET /v1/generate?url=https://example.com&apiKey=your-api-key 
				
			
		POST with raw HTML
				
					POST /v1/generate
{
  "apiKey": "your-api-key",
  "html": "Hello World"
} 
				
			
		
				
					curl -X POST https://api.gen2pdf.com/v1/generate \
  -H "Content-Type: application/json" \
  -d '{
    "apiKey": "your-api-key",
    "url": "https://example.com",
    "filename": "example"
  }' 
				
			
		
				
					 "your-api-key",
  "url" => "https://example.com",
  "filename" => "example"
];
$options = [
  'http' => [
    'header'  => "Content-Type: application/json\r\n",
    'method'  => 'POST',
    'content' => json_encode($data),
  ]
];
$context  = stream_context_create($options);
$response = file_get_contents('https://api.gen2pdf.com/v1/generate', false, $context);
echo $response;
?> 
				
			
		
				
					const fetch = require('node-fetch');
const response = await fetch("https://api.gen2pdf.com/v1/generate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    apiKey: "your-api-key",
    url: "https://example.com",
    filename: "example"
  })
});
const result = await response.json();
console.log(result); 
				
			
		
				
					import requests
data = {
    "apiKey": "your-api-key",
    "url": "https://example.com",
    "filename": "example"
}
response = requests.post("https://api.gen2pdf.com/v1/generate", json=data)
print(response.json()) 
				
			
		
				
					require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://api.gen2pdf.com/v1/generate")
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
request.body = {
  apiKey: "your-api-key",
  url: "https://example.com",
  filename: "example"
}.to_json
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end
puts response.body 
				
			
		
				
					import java.net.http.*;
import java.net.URI;
import java.net.http.HttpRequest.BodyPublishers;
public class PDFGenerator {
  public static void main(String[] args) throws Exception {
    String json = """
      {
        "apiKey": "your-api-key",
        "url": "https://example.com",
        "filename": "example"
      }
    """;
    HttpClient client = HttpClient.newHttpClient();
    HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("https://api.gen2pdf.com/v1/generate"))
      .header("Content-Type", "application/json")
      .POST(BodyPublishers.ofString(json))
      .build();
    HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
    System.out.println(response.body());
  }
}  
				
			
		
				
					package main
import (
  "bytes"
  "encoding/json"
  "fmt"
  "net/http"
)
func main() {
  data := map[string]string{
    "apiKey": "your-api-key",
    "url": "https://example.com",
    "filename": "example",
  }
  jsonData, _ := json.Marshal(data)
  resp, err := http.Post("https://api.gen2pdf.com/v1/generate", "application/json", bytes.NewBuffer(jsonData))
  if err != nil {
    panic(err)
  }
  defer resp.Body.Close()
  var result map[string]interface{}
  json.NewDecoder(resp.Body).Decode(&result)
  fmt.Println(result)
} 
				
			
		We provide an official Gen2PDF WordPress plugin that allows you to generate PDFs directly from your website using a shortcode.
Download Plugin here.
After activating the plugin:
– Go to Settings/Gen2PDF.
– Paste your API key from your Gen2PDF account.
– Save changes.
Shortcode Usage
Use this shortcode anywhere on your site (page, post, widget):
				
					[gen2pdf url="https://example.com" format="A4" landscape="false" filename="custom-file"]