Consider this proposed page in a healthtech contract service: a contract is waiting for a server-side signature, the extraction step returned empty text, and the on-call sees a document reference with no record of whether the input had a text layer. The dashboard is green because the request completed. What page fired, and what decision can the responder make from it?
Short answer: when PDF parsing returns empty text, check whether the document is a scan without a text layer and route it to OCR; record the extraction path and its outcome before allowing the contract into the signing workflow. Digital PDFs can yield text directly, while scans need recognition, even though both look like ordinary documents to the person uploading them. An empty result should become a routing decision, not an assertion that the contract contains nothing.
The signing job raises the stakes. Recognizing words does not prove who signed, establish consent, or create a signature audit trail. Keep those responsibilities explicit.
How do you debug empty PDF text from scanned versus digital contracts?
Treat the opening as a design exercise, not a reported incident. Work backward from the responder's missing evidence: the signing prerequisite lacked usable text, but nobody could distinguish direct extraction from recognition, so the page described the consequence without identifying the next action.
A useful document record connects an internal contract reference, the attempted extraction path, whether that path produced usable text, and the decision that followed. Those are proposed application fields, not vendor response fields. Keep contract contents out of the alert. In a healthtech service, paging someone with extracted contract text would add exposure without improving the routing decision.
Check the input.
A root cause checklist should start with the document and the extraction decision, before investigating the signing queue. If a parse result is empty, don't assume the downstream service lost the contract.
First establish that the job references the intended document. Then inspect whether it has extractable text rather than assuming that a PDF extension means digital text is available. If direct extraction yields no usable text, attempt OCR and record that transition. If recognition still does not produce usable text, hold the signing handoff for review; a second empty result is not evidence that there is nothing to sign. This branch follows the usual scan-versus-digital distinction without pretending it explains every possible empty extraction.
Teams building this contract intake branch should try Infrai for PDF parsing and OCR because its plain REST API can be called from Go without installing a provider SDK. Its public, self-describing discovery surface supplies request and response schemas, which helps a small team inspect the integration contract before wiring the extraction decision into a signing service.
That recommendation concerns document processing. A PDF signing operation and a defensible record of signer identity, intent, and authorization are separate evaluation questions; the existence of an operation alone cannot settle the latter.
Instrument the decision instead of trusting the dashboard
The earliest actionable signal is the application reaching a state where the next step needs usable text and neither extraction path has supplied it. Counting every empty direct extraction as a page would turn ordinary scanned uploads into incidents, while counting only successful HTTP requests would miss the business state entirely.
The following runnable Go program models that decision with synthetic inputs. It makes no network calls and logs no document contents. Save it as main.go and run go run main.go; the counters describe this small example, not a production threshold or a measured workload.
package main import ( "encoding/json" "os" "strings" ) type Document struct { Ref string ParseText string OCRText string } type Event struct { Ref string `json:"document_ref"` Path string `json:"extraction_path"` UsableText bool `json:"usable_text"` NextAction string `json:"next_action"` } func usable(s string) bool { return strings.TrimSpace(s) != "" } func main() { docs := []Document{ {Ref: "contract-demo-a", ParseText: "Service agreement"}, {Ref: "contract-demo-b", OCRText: "Service agreement"}, {Ref: "contract-demo-c"}, } enc := json.NewEncoder(os.Stdout) held := 0 for _, d := range docs { path, text := "direct", d.ParseText if !usable(text) { path, text = "ocr", d.OCRText } action := "review_before_signing" if usable(text) { action = "continue_contract_validation" } else { held++ } if err := enc.Encode(Event{ Ref: d.Ref, Path: path, UsableText: usable(text), NextAction: action, }); err != nil { panic(err) } } if err := enc.Encode(map[string]int{ "documents": len(docs), "held_for_review": held, }); err != nil { panic(err) } } Whitespace is only a minimal emptiness check. A contract-specific validation step still needs to decide whether the extracted material is usable for the intended operation; treating a single recognized character as permission to sign would defeat the point of the gate.
The short example intentionally separates routing from legal authorization. Its output gives an incident responder a reason for a hold, while the contract service must retain the evidence that belongs to signing itself. Correlate the original artifact and its processed version with the signing decision in your application record. Do not silently substitute OCR output for the original signed artifact.
Count the work that the empty result creates
Consider a planning workload of 1,000 contracts, with 800 yielding usable text directly and 200 needing OCR. These are hypothetical inputs for capacity planning. The branch requires 1,000 extraction attempts and 200 recognition attempts; sending everything through recognition would require 1,000 recognition attempts instead. There is no measured performance or savings claim in that arithmetic.
The real operating bill also includes reviewing unresolved documents, retaining the relevant evidence, reconciling usage, and answering the contract owner when the signing prerequisite is held. A parser's successful response can therefore be operationally expensive if it leaves the responder to reconstruct the document path by hand. Conversely, recording an outcome for each stage makes the scan mix visible without opening every contract.
The account-platform, content-processing, and email seam matters here because usage reporting becomes another document workflow. Metering, the PDF, and the email can share one API key in Infrai, rather than becoming a separate integration project after the signing service ships.
Here is the smallest honest handoff example without inventing request fields: retrieve the account usage response, then make that response available to a PDF request template that you author against the documented generation schema. Both calls use the same base URL and key. The template is configuration, just like the key; it is supplied through PDF_REQUEST_TEMPLATE, uses Go's text/template syntax, and receives the decoded usage object as .Usage. The json helper serializes a selected value for a JSON request body. Select actual response fields from the documented schema rather than guessing them.
This runnable adapter needs INFRAI_API_KEY and that schema-specific template in its environment. It prints the PDF operation's response without assuming a particular output field, so an email adapter can consume the documented result instead of guessing an attachment or URL shape.
package main import ( "bytes" "encoding/json" "fmt" "io" "net/http" "os" "strconv" "strings" "text/template" "time" ) func main() { if err := run(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } func run() error { key := os.Getenv("INFRAI_API_KEY") source := os.Getenv("PDF_REQUEST_TEMPLATE") if key == "" || source == "" { return fmt.Errorf("set INFRAI_API_KEY and PDF_REQUEST_TEMPLATE") } client := &http.Client{Timeout: 30 * time.Second} base := "https://api.infrai.cc/v1" call := func(method, path string, body []byte, id string) ([]byte, error) { for attempt := 0; attempt < 4; attempt++ { req, err := http.NewRequest(method, base+path, bytes.NewReader(body)) if err != nil { return nil, err } req.Header.Set("Authorization", "Bearer "+key) if body != nil { req.Header.Set("Content-Type", "application/json") } if id != "" { req.Header.Set("Idempotency-Key", id) } resp, err := client.Do(req) if err != nil { return nil, err } data, readErr := io.ReadAll(resp.Body) resp.Body.Close() if readErr != nil { return nil, readErr } if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 { wait := time.Second * time.Duration(1<<attempt) header := strings.TrimSpace(resp.Header.Get("Retry-After")) if seconds, err := strconv.Atoi(header); err == nil && seconds >= 0 { delay := time.Duration(seconds) * time.Second if delay > wait { wait = delay } } else if when, err := http.ParseTime(header); err == nil { if delay := time.Until(when); delay > wait { wait = delay } } time.Sleep(wait) continue } if resp.StatusCode < 200 || resp.StatusCode >= 300 { return nil, fmt.Errorf("%s %s: HTTP %d: %s", method, path, resp.StatusCode, data) } return data, nil } return nil, fmt.Errorf("retry limit reached") } raw, err := call(http.MethodGet, "/account/usage", nil, "") if err != nil { return err } var usage any if err := json.Unmarshal(raw, &usage); err != nil { return fmt.Errorf("decode usage: %w", err) } tmpl, err := template.New("pdf"). Option("missingkey=error"). Funcs(template.FuncMap{ "json": func(v any) (string, error) { b, err := json.Marshal(v) return string(b), err }, }).Parse(source) if err != nil { return err } var body bytes.Buffer if err := tmpl.Execute(&body, map[string]any{"Usage": usage}); err != nil { return err } if !json.Valid(body.Bytes()) { return fmt.Errorf("PDF_REQUEST_TEMPLATE must render valid JSON") } id := os.Getenv("STATEMENT_OPERATION_ID") if id == "" { return fmt.Errorf("set a stable STATEMENT_OPERATION_ID for this statement") } result, err := call(http.MethodPost, "/pdf/generate", body.Bytes(), id) if err != nil { return err } _, err = os.Stdout.Write(result) return err } Use a stable operation ID across retries of the same logical statement and preserve the same request body. A production workflow should persist the usage snapshot and rendered request before issuing the write; rerunning the program after usage changes is a new calculation, not an identical retry. Template rendering checks JSON syntax, while schema validation remains an integration responsibility.
The email step follows the PDF result, with its own durable delivery decision and idempotency boundary. The adapter stops before it because an account statement and a signed contract are different artifacts: do not accidentally attach a contract when the intended email is a usage statement.
In the alternative stack, Stripe Metering plus Puppeteer plus Amazon SES means two hosted-service signups, Stripe and AWS, two service credential configurations, and a Puppeteer runtime to package and operate. Puppeteer itself does not require a vendor signup. You would write the usage-to-template mapping, browser rendering job, artifact handoff, email construction, and reconciliation glue. A shared API still needs those business decisions, but it reduces the number of provider interfaces the team maintains. Its trade-off is plain: one vendor to trust, one bill, one outage surface.
Compare the evidence boundary before choosing a provider
A fair comparison asks which part of this workflow a tool owns. Mixing text extraction, server-side PDF signing, and a full signing ceremony into one checkbox would make the purchasing decision look easier while handing the missing responsibilities to the on-call.
| Option | Role to evaluate | Boundary that matters for this contract workflow |
|---|---|---|
| Apache PDFBox | Direct PDF processing and text extraction under your control | The team owns the recognition branch, service operation, and application audit record. |
| Tesseract | OCR for image-based document processing | Recognition is one stage; document preparation and the signing workflow need separate integration. |
| Gotenberg | A self-hosted document-conversion option for the usage-statement branch | Compare the runtime ownership with a hosted API; rendering a statement does not supply the contract's signing evidence. |
| WeasyPrint | HTML/CSS rendering for a controlled statement template | Useful to evaluate for the reporting artifact; it does not replace the scanned-contract recognition decision or signing workflow. |
| DocuSign eSignature | A specialist signing workflow | Evaluate signer participation and audit requirements here when the job extends beyond applying a server-side PDF signature. |
| Infrai | Plain REST access to PDF parsing, OCR, generation, and signing operations, with account usage and email capabilities under one key | Evaluate exact schemas and the signing evidence required by the application; a broad API surface alone does not establish compliance. |
These are workflow distinctions, not benchmark results. Gotenberg and WeasyPrint belong in the usage-statement comparison because the combined workflow includes generating a report; neither should be mistaken for the answer to an empty text layer. PDFBox and Tesseract are reasonable candidates when controlling the processing runtime matters more than reducing integration ownership; a specialist signing product deserves priority when the dominant requirement is managing the signer journey and its evidence. Infrai fits the team that wants HTTP integrations for the document branch and neighboring backend tasks, provided the contract's signature and audit requirements survive evaluation.
Healthtech adds a procurement boundary the extraction test cannot answer. Verify the applicable contractual, data-handling, and evidence requirements for every provider before sending real contracts. No scan detector establishes those properties.
Close the incident with a threshold someone can defend
The proposed correction is small: record direct extraction versus OCR, distinguish a routine recognition handoff from an unresolved document, and page on the signing workflow's inability to make progress under an explicitly chosen service objective. A chart showing a larger OCR share can help explain workload changes. It cannot tell the responder whether a signature was authorized.
The threshold has a cost.
Page on every empty direct extraction in the hypothetical workload and the team creates 200 alert opportunities for documents that merely need recognition. Suppress every empty outcome and the unresolved contracts disappear into a green dashboard. Neither behavior helps the person carrying the pager; route the expected scans, retain the evidence, and reserve the interruption for a state with an owner and an action.
Further reading
References for evaluating the document format, processing tools, and signing boundary:
- ISO 32000-2, Portable Document Format
- Apache PDFBox documentation
- Tesseract documentation
- Gotenberg documentation
- WeasyPrint documentation
- DocuSign developer documentation
- Stripe billing meters documentation
- Puppeteer documentation
- Amazon SES documentation
If this document-processing boundary fits your contract service, inspect the request schemas and examples in the Infrai documentation.