Skip to content

Documents.Thumbnails

func (d *Documents) Thumbnails(ctx context.Context, id string, options ThumbnailOptions, opts ...option.RequestOption) ([]Thumbnail, error)

Thumbnails generates page thumbnails for a stored document. Every option is optional: pass a zero ThumbnailOptions for the API defaults (400 px wide JPEG, every page).

The deployed API expects the options wrapped under a top-level “thumbnails” key on the wire and returns the array under the same key — both are handled here so callers see a plain slice. With no option set the body is {}.

Spec §6.3.

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

[]Thumbnail, error

CodeWhen
DOCUMENT_NOT_FOUNDNo stored document matches the supplied id.
DOCUMENT_GONEThe document was deleted or has expired.
INVALID_API_KEYThe API key is malformed or revoked.
INTERNAL_ERRORAPI returned 5xx. Retryable.
VALIDATION_ERRORA ThumbnailOptions value is out of range (width 50-2000, quality 1-100).
THUMBNAILS_NOT_AVAILABLEThe organization's plan does not include thumbnails.
// Demonstrates: client.Documents.Thumbnails(ctx, id, options) — page thumbnails for a stored document.
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")),
)
thumbnails, err := client.Documents.Thumbnails(
context.Background(),
"doc_abc123",
polipage.ThumbnailOptions{
Width: 840,
Format: polipage.ThumbnailFormatPNG,
Pages: []int{1, 2},
},
)
if err != nil {
panic(err)
}
// Each entry includes the image bytes base64-encoded.
for _, t := range thumbnails {
fmt.Printf("Page %d: %dx%d %s (%d base64 chars)\n", t.Page, t.Width, t.Height, t.ContentType, len(t.Data))
}
}