Complete Go code examples for the PixDoc API
# Uses Go's standard library — no dependenciesSend HTML to the /api/v1/pdf endpoint and save the binary response.
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
)
func main() {
body, _ := json.Marshal(map[string]string{"html": "<h1>Hello World</h1>"})
req, _ := http.NewRequest("POST", "https://pixdoc.dev/api/v1/pdf", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("output.pdf")
io.Copy(out, resp.Body)
}The /api/v1/screenshot endpoint returns a PNG image.
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
)
func main() {
body, _ := json.Marshal(map[string]string{"html": "<h1>Hello World</h1>"})
req, _ := http.NewRequest("POST", "https://pixdoc.dev/api/v1/screenshot", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("screenshot.png")
io.Copy(out, resp.Body)
}Pass a template_id and variables instead of raw HTML.
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
)
func main() {
payload := map[string]interface{}{
"template_id": "invoice",
"variables": map[string]string{
"company": "Acme Corp",
"total": "$1,250.00",
},
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://pixdoc.dev/api/v1/pdf", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("invoice.pdf")
io.Copy(out, resp.Body)
}