Skip to main content

Quick Start for Go

Go

Integrate PDFBolt's REST API in Go to generate PDFs from URLs, HTML, or templates. The examples below cover all three conversion modes (Direct, Sync, Async).

1. Get Your API Key

Find your API key on the API Keys page in your Dashboard. If you don't have an account, sign up – the free plan includes 100 document conversions per month.

2. Make Your First Request

Any HTTP client works – adjust the request structure to match your library.

Examples use the built-in net/http and encoding/json packages.

Choose your endpoint:

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

Choose your source:

Convert a webpage to PDF:

package main

import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
)

func main() {
data := map[string]interface{}{
"url": "https://example.com",
"format": "A4",
"printBackground": true,
}
jsonBody, err := json.Marshal(data)
if err != nil {
log.Fatal(err)
}

req, err := http.NewRequest("POST", "https://api.pdfbolt.com/v1/direct", bytes.NewReader(jsonBody))
if err != nil {
log.Fatal(err)
}
req.Header.Add("API-KEY", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
req.Header.Add("Content-Type", "application/json")

resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("HTTP %d\n", resp.StatusCode)
fmt.Printf("Error Message: %s\n", string(body))
return
}

file, err := os.Create("webpage.pdf")
if err != nil {
log.Fatal(err)
}
defer file.Close()

if _, err := io.Copy(file, resp.Body); err != nil {
log.Fatal(err)
}
fmt.Println("PDF generated successfully")
}

Next Steps



Related reading