PDF4.dev
Quickstart

Go

Prerequisites

1. Create a template

Go to the dashboard and click New template. Note the template ID or slug.

2. Render a PDF

main.go
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")
}
Run
go run main.go

Next steps