Skip to content

RenderToFile

func RenderToFile(ctx context.Context, c *Client, in RenderInput, path string) error

RenderToFile 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.

NameTypeRequiredDescription
ctxcontext.Contextrequired(no description)
c*Clientrequired(no description)
inRenderInputrequired(no description)
pathstringrequired(no description)

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.
DOWNLOAD_FAILEDPresigned URL fetch failed.
io_failedLocal filesystem write failed.
// 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")
}