Render.Document
func (r *Render) Document(ctx context.Context, in RenderInput, opts ...option.RequestOption) (*DocumentDescriptor, error)Document renders a PDF, stores it server-side, and returns the descriptor. The PDF bytes are NOT fetched — call (*DocumentDescriptor).DownloadPDF when you need them, or use Render.PDF / Render.PDFStream for the one-call shortcut.
The API renders the project’s copy published in the API key’s environment. Variadic options apply per-call; the most useful one is option.WithIdempotencyKey when the caller has a natural identifier (e.g. an invoice number) and wants to override the auto-generated UUID4.
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”*DocumentDescriptor, 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. |
PROJECT_REQUIRED_FOR_DOCUMENT | RenderInput.Project is empty (`project is required`), checked before any request. |
Example
Section titled “Example”// Demonstrates: client.Render.Document(ctx, in) — render and store a PDF server-side.package main
import ( "context" "fmt" "os"
polipage "github.com/poli-page/sdk-go" "github.com/poli-page/sdk-go/option")
func main() { ctx := context.Background() client := polipage.NewClient( option.WithAPIKey(os.Getenv("POLI_PAGE_API_KEY")), )
doc, err := client.Render.Document(ctx, polipage.RenderInput{ Project: "billing", Template: "invoice", Data: map[string]any{"invoiceNumber": "INV-001", "total": 1280}, Metadata: polipage.RenderMetadata{"customerId": "cust_42"}, }) if err != nil { panic(err) }
// doc.DocumentID identifies the stored document — use it with // client.Documents.* to fetch, preview, thumbnail, or delete later. fmt.Printf("Stored as %s (%d pages, %d bytes)\n", doc.DocumentID, doc.PageCount, doc.SizeBytes)
// Fetch the PDF bytes on demand: pdf, err := doc.DownloadPDF(ctx) if err != nil { panic(err) } fmt.Printf("Downloaded %d bytes\n", len(pdf))}