Skip to content

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.

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

io.ReadCloser, 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.
// 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
}