RenderToFile
func RenderToFile(ctx context.Context, c *Client, in RenderInput, path string) errorRenderToFile renders a PDF and streams the bytes straight to disk. Parent directories are created if missing; an existing file at path is overwritten. Memory-bounded — streaming via io.Copy regardless of PDF size.
Errors from the render call propagate as-is (typed *Error). I/O errors surface as *Error with Code == ErrCodeInvalidOptions and the underlying os error wrapped in Cause — use errors.Unwrap to inspect.
Method order matches the spec: callers should reuse a single *Client across calls. RenderToFile is a free function because it is a thin convenience over Render.PDFStream; keeping it off *Client matches the platform spec §2.
Parameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | required | (no description) |
c | *Client | required | (no description) |
in | RenderInput | required | (no description) |
path | string | required | (no description) |
Returns
Section titled “Returns”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. |
io_failed | Local filesystem write failed. |
Example
Section titled “Example”// Demonstrates: polipage.RenderToFile(ctx, client, in, path) — streams a PDF to disk.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")), )
err := polipage.RenderToFile( context.Background(), client, polipage.RenderInput{ Project: "billing", Template: "invoice", Data: map[string]any{"invoiceNumber": "INV-001", "total": 1280}, }, "./invoices/INV-001.pdf", ) if err != nil { panic(err) }
// Streams response bytes directly to disk with bounded memory. // Parent directories are created automatically. fmt.Println("Wrote ./invoices/INV-001.pdf")}