Developer quickstart
Generate PDFs in Go
Post structured document data with net/http and stream a successful PDF response to a file.
Prerequisites
- A PDFDesignAPI account and API token.
- A template UUID with a schema and at least one data binding.
- Trusted server-side code where the token remains secret.
Generate and save the PDF
payload := strings.NewReader(
`{"data":{"customer":{"name":"Example BV"}}}`)
req, err := http.NewRequestWithContext(ctx, http.MethodPost,
"https://pdfdesignapi.com/api/v1/generate/single/"+templateUUID,
payload)
if err != nil { return err }
req.Header.Set("Authorization", "Bearer "+apiToken)
req.Header.Set("Content-Type", "application/json")
res, err := httpClient.Do(req)
if err != nil { return err }
defer res.Body.Close()
if res.StatusCode < 200 || res.StatusCode >= 300 {
body, _ := io.ReadAll(io.LimitReader(res.Body, 1<<20))
return fmt.Errorf("PDF generation failed: %s: %s", res.Status, body)
}
file, err := os.Create("document.pdf")
if err != nil { return err }
defer file.Close()
_, err = io.Copy(file, res.Body)
return errProduction notes
- Use an http.Client with explicit timeouts and reuse it across requests.
- Limit error-body reads before logging a redacted response.
- Propagate request cancellation through the context.