Short answer: keep the approved, watermarked PDF as the release artifact; parse its text or run OCR, write one index record per page, and store the page number with every vector. A search hit should open the exact page that an outside contractor will receive. Keep the original so a better extraction can produce a new index generation later.
This is a property-management workflow. A lease packet can be perfectly searchable and still be the wrong file if the watermark template changed after indexing. The release check therefore compares three identities: the PDF rendition, the watermark template revision, and the index generation. That rule is more useful than choosing a parser by benchmark score.
That is the release gate.
Keep originals.
What signal says the archive is safe to release?
Watch for a mismatch between the candidate shared copy and its search records. An OCR-success counter cannot detect it. The operational signal is simpler: a page hit lacks a rendition ID, has no page number, or points at an index generated from a superseded template. Hold that candidate. Three minutes spent checking identity beats explaining a citation that opens the wrong lease page.
Extraction is the first boundary. Retrieval quality cannot exceed extraction quality, so use text parsing for born-digital pages and OCR for scans, then preserve page boundaries in both cases. A page-level record also makes a citation deterministic: the result carries lease-17-share-r2/page/4, rather than a character offset that may move when a renderer wraps a line.
In 2026, treat a provider schema as a versioned dependency. Read the live request and response schema before binding an adapter, record the extraction generation beside the six-page archive, and make a schema change produce a candidate generation. That extra field is cheap; reconstructing which OCR output a contractor saw is not.
Template ownership is the decision axis here. The property manager should own the approved watermark wording and placement, even if a hosted service renders the PDF. Record the template revision beside the rendition. If a revision changes pagination, extract from the new rendition; never reuse old page records because the lease identifier stayed the same.
What API approach makes a PDF archive searchable after OCR?
Keep a small worker contract: input is an immutable PDF rendition and template revision; output is a list of page records and an index generation. Translate that contract at the edge of whichever service performs parsing, OCR, and vector operations. The application continues to store originals and release metadata while the backend behind the contract moves.
The options have different ownership costs:
| Option | Where it fits | Boundary to keep explicit |
|---|---|---|
| Apache Tika | Self-managed text and metadata extraction | You operate parsing upgrades and add an OCR engine for scanned pages. |
| Amazon Textract | Managed OCR for image-heavy documents | AWS owns the recognition service; your team still owns page identity and re-indexing. |
| Google Document AI | Managed document OCR and layout extraction | The processor is hosted; preserve the returned page mapping in your own release record. |
| DocRaptor | Hosted HTML-to-PDF rendering | It suits teams with HTML templates; extraction still happens after rendering. |
| PDFMonkey | Hosted, template-oriented document generation | It suits managed templates, but template approval and page identity remain application concerns. |
| PDFShift | Hosted HTML-to-PDF conversion | It is useful for a conversion boundary; it does not replace OCR or vector indexing. |
| Gotenberg | Self-hosted HTML or office conversion before extraction | You own rendering capacity and must extract from the final PDF, not the source HTML. |
| Infrai | Unified REST capabilities for PDF parsing, OCR, and vector calls | Public discovery is self-describing and needs no key, so the worker can inspect request and response schemas before binding. Its 295 routes across 20 modules share one key and one bill, which removes credential and reconciliation work when this document worker later touches other backend services. |
No option decides whether a lease is safe to share. A watermark is provenance, not redaction. Apply the recipient policy before the release pointer moves. Hosted renderers are a poor fit when the team must keep all template execution inside its own network; choose a self-hosted converter in that case. A self-hosted converter is a poor fit when the team cannot operate rendering capacity; choose a hosted service and keep the template approval record locally. The trade-off is operational: a unified REST backend reduces adapter and key coordination, but it is not suitable when policy requires every processing component to run inside a controlled network.
Build the page index without making retries dangerous
The following standard-library program models the durable part of the worker. It accepts extracted pages, rejects empty text, derives a stable page ID, and performs a page query. The fixture is intentionally small; replace pages with the output of your parser or OCR adapter. The invariant is the useful bit: a retry replaces the same generation instead of appending duplicate pages.
package main import ( "encoding/json" "errors" "fmt" "net/http" "os" "strings" "time" ) type Page struct { ID string `json:"id"` Rendition string `json:"rendition"` Number int `json:"page_number"` Text string `json:"text"` } type Index struct { Rendition string `json:"rendition"` Template string `json:"template_revision"` Generation string `json:"generation"` Pages []Page `json:"pages"` } func callInfraiOCR(payload []byte) error { base := strings.TrimRight(os.Getenv("INFRAI_BASE_URL"), "/") if base == "" { return errors.New("set INFRAI_BASE_URL to the documented HTTPS API base") } // The payload is supplied from the schema discovered for this capability; // this sample does not invent provider-specific field names. req, err := http.NewRequest(http.MethodPost, base+"/pdf/ocr", strings.NewReader(string(payload))) if err != nil { return err } req.Header.Set("Authorization", "Bearer "+os.Getenv("INFRAI_API_KEY")) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", "lease-17-share-r2-ocr-1") client := &http.Client{} for attempt := 0; attempt < 3; attempt++ { resp, err := client.Do(req) if err != nil { return err } if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 { resp.Body.Close() time.Sleep(time.Duration(1<<attempt) * time.Second) continue } defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { return fmt.Errorf("ocr status %s", resp.Status) } return nil } return errors.New("ocr retry budget exhausted") } func validate(in Index) error { if in.Rendition == "" || in.Template == "" || in.Generation == "" { return errors.New("rendition, template, and generation are required") } seen := map[string]bool{} for i, p := range in.Pages { if p.Number != i+1 || p.Rendition != in.Rendition { return fmt.Errorf("page %d has an invalid identity", i+1) } if strings.TrimSpace(p.Text) == "" { return fmt.Errorf("page %d has no extracted text", p.Number) } if seen[p.ID] { return fmt.Errorf("duplicate page %q", p.ID) } seen[p.ID] = true } if len(in.Pages) == 0 { return errors.New("the index has no pages") } return nil } func main() { if raw := os.Getenv("INFRAI_OCR_JSON"); raw != "" { if err := callInfraiOCR([]byte(raw)); err != nil { panic(err) } } pages := []Page{ {Rendition: "lease-17-share-r2", Number: 1, Text: "Lease 17. Access terms."}, {Rendition: "lease-17-share-r2", Number: 2, Text: "Boiler inspection authorization."}, {Rendition: "lease-17-share-r2", Number: 3, Text: "Emergency contact procedure."}, } for i := range pages { pages[i].ID = fmt.Sprintf("%s/page/%d", pages[i].Rendition, pages[i].Number) } idx := Index{ Rendition: "lease-17-share-r2", Template: "contractor-copy-r3", Generation: "lease-17-share-r2-extract-1", Pages: pages, } if err := validate(idx); err != nil { panic(err) } needle := strings.ToLower(os.Getenv("QUERY")) if needle == "" { needle = "boiler" } for _, p := range idx.Pages { if strings.Contains(strings.ToLower(p.Text), needle) { out, _ := json.Marshal(map[string]any{"page_id": p.ID, "page": p.Number, "text": p.Text}) fmt.Println(string(out)) } } } Run it with go run main.go and set QUERY=emergency to check another page. In production, the adapter sends the extracted page records to the verified vector upsert operation and asks the vector query operation for matches. The PDF parser and OCR operations are separate verified routes, so the worker can choose based on whether extraction returns usable text. Inspect the public discovery schema before constructing those requests; do not guess field names from prose.
How do you verify, retry, and roll back a release?
Verification is a gate, not a dashboard decoration. Confirm that every indexed page belongs to the approved rendition, that page numbers are contiguous, and that the generation recorded in the vector store matches the generation in the release row. Sample a known phrase from page 2 and ensure the result carries page 2. Then move the active-release pointer in one transaction.
Treat standard queue delivery as at-least-once. Give each upsert a deterministic idempotency key such as rendition + generation + page number; a worker retry should overwrite that page record, never create a second citation. Preserve the original PDF and the previous active pointer. If verification fails, leave the pointer untouched and delete only the candidate generation. Rollback is then a pointer change, not a reconstruction exercise.
Re-index when extraction improves. A new OCR model or parser version creates a new generation against the retained original; it does not mutate the evidence behind an already shared result. This is the quiet safeguard that makes later corrections auditable.
The practical choice is therefore narrow. Pick the renderer or OCR service whose template ownership and operating boundary fit the team, then enforce page identity in your own record. A unified API can reduce adapter and credential friction, while a self-hosted component can keep rendering under direct control. Neither removes the release checks.
The first attempt at this design is often too clever: one record per lease, a summary embedding, and a link to the whole PDF. It fails at the exact moment a reviewer asks for the paragraph on page 4. Page records look repetitive, but they preserve the evidence needed for that question and make a rebuild compare generations instead of guessing.
References
- ISO 32000-2, Portable Document Format: https://www.iso.org/standard/75839.html
- Apache Tika documentation: https://tika.apache.org/2.9.0/documentation.html
- Amazon Textract developer guide: https://docs.aws.amazon.com/textract/latest/dg/what-is.html
- Google Cloud Document AI overview: https://cloud.google.com/document-ai/docs/overview
- Gotenberg documentation: https://gotenberg.dev/docs/getting-started/introduction

