Skip to content

Documents.Preview

func (d *Documents) Preview(ctx context.Context, id string, opts ...option.RequestOption) (*DocumentPreviewResult, error)

Preview retrieves a stored document’s paginated HTML. The engine does no work — this is a cheap read.

The deployed API returns the HTML as text/html (not a JSON envelope) and the page count via the X-Document-Page-Count response header. Missing or unparseable headers are tolerated: PageCount defaults to 0.

Spec §6.2.

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

*DocumentPreviewResult, 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.
// Demonstrates: client.Documents.Preview(ctx, id) — get a stored document's HTML preview.
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")),
)
preview, err := client.Documents.Preview(context.Background(), "doc_abc123")
if err != nil {
panic(err)
}
// preview.HTML is the server-rendered HTML with the stored document's data
// applied to its template — useful for in-browser previews without a PDF.
fmt.Printf("Preview: %d pages, HTML length %d\n", preview.PageCount, len(preview.HTML))
}