Quickstart
Go
Prerequisites
- A PDF4.dev account — sign up free
- An API key from Settings
- Go 1.21+
1. Create a template
Go to the dashboard and click New template. Note the template ID or slug.
2. Render a PDF
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
payload, _ := json.Marshal(map[string]any{
"template_id": "invoice",
"data": map[string]string{
"company_name": "Acme Corp",
"invoice_number": "INV-2025-001",
"total": "$4,500.00",
},
})
req, _ := http.NewRequest("POST", "https://pdf4.dev/api/v1/render", bytes.NewBuffer(payload))
req.Header.Set("Authorization", "Bearer p4_live_your_key_here")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
panic(fmt.Sprintf("API error: %s", body))
}
pdf, _ := io.ReadAll(resp.Body)
os.WriteFile("invoice.pdf", pdf, 0644)
fmt.Println("PDF saved to invoice.pdf")
}go run main.goNext steps
- PDF format — page size, margins, custom dimensions
- API reference — full render endpoint docs