GoodMemGoodMem
ReferenceSdkV2.NET

OCR

Document OCR — text extraction from PDFs / images.

Namespace: Goodmem.Client.Api · Class: OcrApi

Reach this surface as client.Ocr on a GoodmemClient. Every network method is asynchronous — it returns a Task<T> (or an IAsyncEnumerable<T> for pagination and streaming) and accepts a CancellationToken; the Async suffix marks the standard .NET Task-based async pattern.

Methods

MethodSummary
DocumentAsyncRun OCR on a document or image.
DocumentFromFileAsyncRun OCR over a local file. Any Content on is replaced by the file's base64-encoded bytes; other fields (page range, markdown, …) are preserved. The caller's request is never mutated.

DocumentAsync

Run OCR on a document or image. Pass base64-encoded document bytes as content. The server auto-detects format; set format explicitly only if needed.

Declaration

public Task<OcrDocumentResponse> DocumentAsync(OcrDocumentRequest request, CancellationToken ct = default)

HTTPPOST /v1/ocr:document

Parameters

TypeNameDescription
OcrDocumentRequestrequestThe request payload; the linked model lists every field and its JSON wire name.
CancellationTokenctCancellation / deadline signal for the call. (optional)

Returns

Task<OcrDocumentResponse> — an awaitable that resolves to OcrDocumentResponse.

Exceptions

TypeCondition
ArgumentNullExceptionrequest is null.
NetworkExceptionThe request could not reach the server (DNS, connection, or TLS failure).
ApiExceptionThe server returned a non-success (non-2xx) status. A status-specific subtype is thrown where it applies — e.g. NotFoundException (404), PermissionDeniedException (403), ConflictException (409).

Example

var imageB64 = Convert.ToBase64String(Encoding.UTF8.GetBytes("not-a-real-image"));
var result = await client.Ocr.DocumentAsync(
    new OcrDocumentRequest
    {
        Content = imageB64,
        Format = OcrInputFormat.Png,
        IncludeMarkdown = true,
    }
);
Console.WriteLine(result.PageCount);


DocumentFromFileAsync

Run OCR on a document or image. Pass base64-encoded document bytes as content. The server auto-detects format; set format explicitly only if needed.

File overload: reads filePath from disk (memory-create uploads it as a multipart file part; OCR base64-encodes it into the JSON body) — the content type is inferred from the extension.

Declaration

public Task<OcrDocumentResponse> DocumentFromFileAsync(string filePath, OcrDocumentRequest? request = null, CancellationToken ct = default)

HTTPPOST /v1/ocr:document

Parameters

TypeNameDescription
stringfilePathPath to a local file; it is read into memory and (for OCR) base64-encoded, with the content type inferred from the extension.
OcrDocumentRequestrequestThe request payload; the linked model lists every field and its JSON wire name. (optional)
CancellationTokenctCancellation / deadline signal for the call. (optional)

Returns

Task<OcrDocumentResponse> — an awaitable that resolves to OcrDocumentResponse.

Exceptions

TypeCondition
ArgumentExceptionfilePath is null or empty.
GoodmemExceptionThe local file could not be read (I/O error, missing file, or access denied).
NetworkExceptionThe request could not reach the server (DNS, connection, or TLS failure).
ApiExceptionThe server returned a non-success (non-2xx) status. A status-specific subtype is thrown where it applies — e.g. NotFoundException (404), PermissionDeniedException (403), ConflictException (409).

Example

var result = await client.Ocr.DocumentFromFileAsync("/path/to/document.pdf", new OcrDocumentRequest());


Data Models

Types in the Goodmem.Client.Models namespace. Each row lists the C# property, its type, the JSON wire name, and a description.

OcrDocumentRequest

Request body for OCR document processing.

PropertyTypeJSON (wire)Description
ContentstringcontentBase64-encoded document bytes
FormatOcrInputFormatformatInput format hint (AUTO, PDF, TIFF, PNG, JPEG, BMP) (optional)
IncludeRawJsonboolincludeRawJsonInclude raw OCR JSON payload in the response (optional)
IncludeMarkdownboolincludeMarkdownInclude markdown rendering in the response (optional)
StartPageintstartPage0-based inclusive start page (optional)
EndPageintendPage0-based inclusive end page (optional)

OcrInputFormat

OCR input format hint.

String enum: "AUTO" · "PDF" · "TIFF" · "PNG" · "JPEG" · "BMP"

OcrDocumentResponse

Response containing page-ordered OCR results.

PropertyTypeJSON (wire)Description
DetectedFormatOcrInputFormatdetectedFormatDetected input format
PageCountintpageCountNumber of pages processed after applying the range
PagesIReadOnlyList<OcrPageResult>pagesOrdered per-page OCR results
TimingsDocumentTimingstimingsAggregate timing statistics

OcrPageResult

Per-page OCR result containing output or error status.

PropertyTypeJSON (wire)Description
PageIndexintpageIndex0-based page index
PageOcrPagepageOCR output for the page (optional)
StatusRpcStatusstatusError status for the page (optional)

DocumentTimings

Aggregate timing statistics for an OCR request.

PropertyTypeJSON (wire)Description
WallTimeMslongwallTimeMsEnd-to-end request time (ms)
SumQueueWaitMslongsumQueueWaitMsSum of per-page queue wait times (ms)
SumRenderMslongsumRenderMsSum of per-page render times (ms)
SumOcrMslongsumOcrMsSum of per-page OCR times (ms)
SumPageTotalMslongsumPageTotalMsSum of per-page total times (ms)

OcrPage

OCR output for a single page.

PropertyTypeJSON (wire)Description
RawJsonstringrawJsonRaw OCR JSON payload when requested (optional)
MarkdownstringmarkdownMarkdown rendering when requested (optional)
LayoutOcrLayoutlayoutParsed layout output
TimingsPageTimingstimingsTiming breakdown for the page
ImageImageInfoimageRendered image metadata

RpcStatus

Status payload for per-page OCR errors.

PropertyTypeJSON (wire)Description
CodeintcodegRPC status code as defined by google.rpc.Code
MessagestringmessageHuman-readable error message (optional)

OcrLayout

Parsed OCR layout output for a page.

PropertyTypeJSON (wire)Description
CellsIReadOnlyList<OcrCell>cellsLayout cells in reading order

PageTimings

Per-page timing breakdown for OCR processing.

PropertyTypeJSON (wire)Description
QueueWaitMslongqueueWaitMsTime spent waiting in the render queue (ms)
RenderMslongrenderMsTime spent rendering the page image (ms)
OcrMslongocrMsTime spent running OCR (ms)
TotalMslongtotalMsTotal page processing time (ms)

ImageInfo

Rendered image metadata for an OCR page.

PropertyTypeJSON (wire)Description
WidthPxintwidthPxRendered image width in pixels
HeightPxintheightPxRendered image height in pixels
DpiintdpiRendering DPI

OcrCell

Single OCR layout element.

PropertyTypeJSON (wire)Description
BboxBoundingBoxbboxBounding box in page coordinates (optional)
CategoryLabelstringcategoryLabelRaw category label emitted by OCR
CategoryOcrCategorycategoryNormalized OCR category
TextstringtextOCR text content

BoundingBox

Bounding box coordinates in page space.

PropertyTypeJSON (wire)Description
X1doublex1Left coordinate
Y1doubley1Top coordinate
X2doublex2Right coordinate
Y2doubley2Bottom coordinate

OcrCategory

Normalized OCR layout category.

String enum: "UNSPECIFIED" · "CAPTION" · "FOOTNOTE" · "FORMULA" · "LIST_ITEM" · "PAGE_FOOTER" · "PAGE_HEADER" · "PICTURE" · "SECTION_HEADER" · "TABLE" · "TEXT" · "TITLE" · "OTHER" · "UNKNOWN"