Skip to content

Render.PDF

func (r *Render) PDF(ctx context.Context, in RenderInput, opts ...option.RequestOption) ([]byte, error)

PDF renders a PDF and returns the raw bytes. Two HTTP calls under the hood: POST /v1/render to produce a stored document, then GET PresignedPDFURL to fetch the bytes.

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

[]byte, 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.PDF(ctx, in) — renders the project's copy published in the key's environment.
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")),
)
pdf, err := client.Render.PDF(context.Background(), polipage.RenderInput{
Project: "billing",
Template: "invoice",
Data: map[string]any{"invoiceNumber": "INV-001", "total": 1280},
})
if err != nil {
panic(err)
}
// pdf is a []byte of PDF bytes.
fmt.Printf("Rendered %d bytes\n", len(pdf))
}