Skip to content

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.

NameTypeRequiredDescription
ctxcontext.Contextrequired(no description)
inRenderInputrequired(no description)
opts...option.RequestOption—(no description)

*DocumentDescriptor, error

CodeWhen
VALIDATION_ERRORRequest body failed validation.
PROJECT_NOT_FOUNDNo project matches the slug.
PROJECT_NOT_IN_ENVIRONMENTThe project is not published in the key's environment.
TEMPLATE_NOT_FOUNDThe published project has no template with that slug.
QUOTA_EXCEEDEDMonthly quota reached (429). Not retryable: it lasts until the monthly reset.
RATE_LIMIT_EXCEEDEDToo many requests. Retryable.
PUBLISH_IN_PROGRESSA publish holds the project in the key's environment. Retryable after Retry-After.
timeoutPer-request deadline exceeded. Retryable.
network_errorTCP/TLS failure reaching the API. Retryable.
INTERNAL_ERRORAPI returned 5xx. Retryable.
PROJECT_REQUIRED_FOR_DOCUMENTRenderInput.Project is empty (`project is required`), checked before any request.
// 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))
}