Render.PDFStream
func (r *Render) PDFStream(ctx context.Context, in RenderInput, opts ...option.RequestOption) (io.ReadCloser, error)PDFStream is like Render.PDF but returns the PDF as an io.ReadCloser so the caller can stream it directly to an HTTP response, an S3 upload, or a file without buffering.
The caller MUST close the returned ReadCloser when done, even on early return paths.
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”io.ReadCloser, 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.PDFStream(ctx, in) — renders the project's copy published in the key's environment.package main
import ( "context" "io" "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")), )
body, err := client.Render.PDFStream(context.Background(), polipage.RenderInput{ Project: "billing", Template: "invoice", Data: map[string]any{"invoiceNumber": "INV-001", "total": 1280}, }) if err != nil { panic(err) } defer func() { _ = body.Close() }()
// Stream directly to an HTTP response writer, an S3 multipart upload, or any // io.Writer — bounded memory regardless of PDF size. n, err := io.Copy(io.Discard, body) if err != nil { panic(err) } _ = n}