Render.PDF
func (r *Render) PDF(ctx context.Context, in RenderInput, opts ...option.RequestOption) ([]byte, error)PDF renders a PDF and returns the raw bytes. Two HTTP calls under the hood: POST /v1/render to produce a stored document, then GET PresignedPDFURL to fetch the bytes.
Parameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | required | (no description) |
in | RenderInput | required | (no description) |
opts | ...option.RequestOption | — | (no description) |
Returns
Section titled “Returns”[]byte, error
Errors
Section titled “Errors”| Code | When |
|---|---|
VALIDATION_ERROR | Request body failed validation. |
PROJECT_NOT_FOUND | No project matches the slug. |
PROJECT_NOT_IN_ENVIRONMENT | The project is not published in the key's environment. |
TEMPLATE_NOT_FOUND | The published project has no template with that slug. |
QUOTA_EXCEEDED | Monthly quota reached (429). Not retryable: it lasts until the monthly reset. |
RATE_LIMIT_EXCEEDED | Too many requests. Retryable. |
PUBLISH_IN_PROGRESS | A publish holds the project in the key's environment. Retryable after Retry-After. |
timeout | Per-request deadline exceeded. Retryable. |
network_error | TCP/TLS failure reaching the API. Retryable. |
INTERNAL_ERROR | API returned 5xx. Retryable. |
DOWNLOAD_FAILED | Presigned URL fetch failed. |
Example
Section titled “Example”// Demonstrates: client.Render.PDF(ctx, in) — renders the project's copy published in the key's environment.package main
import ( "context" "fmt" "os"
polipage "github.com/poli-page/sdk-go" "github.com/poli-page/sdk-go/option")
func main() { client := polipage.NewClient( option.WithAPIKey(os.Getenv("POLI_PAGE_API_KEY")), )
pdf, err := client.Render.PDF(context.Background(), polipage.RenderInput{ Project: "billing", Template: "invoice", Data: map[string]any{"invoiceNumber": "INV-001", "total": 1280}, }) if err != nil { panic(err) }
// pdf is a []byte of PDF bytes. fmt.Printf("Rendered %d bytes\n", len(pdf))}