> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/eventos/extractionfinish.md).

# extractionFinish

Document extraction completed successfully.

## Details

Emitted when document extraction completes with all expected data.

**Event:** `extractionFinish`

**Type:** `FacephiSelphidWidgetCustomEvent<SelphidExtractionFinishEvent>` | `CustomEvent<SelphidExtractionFinishEvent>`

### Syntax

```typescript
selphid.addEventListener('extractionFinish', onExtractionFinish);
```

### Received object

The useful payload is of type `SelphidExtractionFinishDetail` and is in `event.detail.detail`:

* `eventType` (`string`): Type of event emitted.
* `cameraId` (`string`): ID of the camera used.
* `result` (`object`): Extraction results.
  * `alphabetUsed` (`string` | `null`): Alphabet used for the extraction (optional).
  * `diagnostic` (`number`): Extraction diagnostic code.
  * `detectionStatus` (`object`): Status of the detected document.
    * `status` (`number`): Extraction status.
    * `quad` (`object`): Position of the document in the frame (optional).
      * `topLeft` (`{ x, y }`): Top-left corner.
      * `topRight` (`{ x, y }`): Top-right corner.
      * `bottomLeft` (`{ x, y }`): Bottom-left corner.
      * `bottomRight` (`{ x, y }`): Bottom-right corner.
    * `glare` (`boolean`): Glare detected on the document (optional).
    * `internalStatus` (`object` ): Internal engine state.
      * `standard` (`number` ): Standard status code.
  * `extractionData` (`object` ): Structured OCR fields.
    * `firstName` (`string` ): First name.
    * `lastName` (`string` ): Last name.
    * `fullName` (`string` ): Full name (optional).
    * `gender` (`string` ): Gender.
    * `nationality` (`string` ): Nationality.
    * `dateOfBirth` (`string` ): Date of birth.
    * `placeOfBirth` (`string` ): Place of birth.
    * `documentId` (`string` ): Document identifier.
    * `documentNumber` (`string` ): Document number.
    * `dateOfExpiry` (`string` ): Expiration date.
    * `dateOfIssue` (`string` ): Issue date.
    * `address` (`string` ): Address.
    * `documentType` (`number` ): Document type (numeric code).
    * `documentTypeString` (`string` ): Document type (text).
    * `isSingleSideDocument` (`boolean`): Indicates whether the document is single-sided.
    * `residencePermitType` (`string`): Residence permit type (optional).
    * `visaType` (`string`): Visa type (optional).
    * `debug1` (`number`): Internal debugging field.
    * `documentCountryIssuer` (`string`): Document-issuing country.
    * `documentCountryIssuerIso2` (`string`): ISO-2 code of the issuing country.
    * `documentCountryIssuerIso3` (`string`): ISO-3 code of the issuing country (optional).
    * `section` (`string`): Document section (optional).
    * `serie` (`string`): Document series (optional).
  * `extractionRaw` (`object`): Raw data extracted from the document.
    * `mrz` (`object`): MRZ data.
      * `rawData` (`string`): Raw MRZ line.
      * `opt1` (`string`): MRZ optional field 1.
      * `opt2` (`string`): MRZ optional field 2.
      * `firstName` (`string` ): First name.
      * `lastName` (`string` ): Last name.
      * `documentId` (`string` ): Document identifier.
      * `documentNumber` (`string` ): Document number.
      * `documentIssuer` (`string`): Document issuer.
      * `dateOfExpiry` (`string` ): Expiration date.
      * `dateOfBirth` (`string` ): Date of birth.
      * `gender` (`string` ): Gender.
      * `nationality` (`string` ): Nationality.
    * `ocr` (`object`): OCR data.
      * `firstName` (`string` ): First name.
      * `lastName` (`string` ): Last name.
      * `fullName` (`string` ): Full name (optional).
      * `documentId` (`string` ): Document identifier.
      * `documentNumber` (`string` ): Document number.
      * `dateOfBirth` (`string` ): Date of birth.
      * `dateOfExpiry` (`string` ): Expiration date.
      * `dateOfIssue` (`string` ): Issue date.
      * `gender` (`string` ): Gender.
      * `nationality` (`string` ): Nationality.
  * `images` (`object`): Cropped images of the document.
    * `frontDocument` (`string` | `null` | `undefined`): Front.
    * `backDocument` (`string` | `null` | `undefined`): Back.
    * `faceImage` (`string` | `null` | `undefined`): Face on the document.
    * `signatureImage` (`string` | `null` | `undefined`): Signature.
  * `imagesFullsize` (`object`): Full-size images.
    * `frontDocument` (`string` | `null` | `undefined`): Full front.
    * `backDocument` (`string` | `null` | `undefined`): Full back.
  * `imagesRaw` (`object`): Raw images (`ImageData`).
    * `frontDocument` (`ImageData` | `null` | `undefined`): Raw front.
    * `backDocument` (`ImageData` | `null` | `undefined`): Raw back.
    * `faceImage` (`ImageData` | `null` | `undefined`): Raw face.
    * `signatureImage` (`ImageData` | `null` | `undefined`): Raw signature.
  * `barCodeExtractionDataFrontDocument` (`object`): Front document barcode data (optional).
    * `firstName` (`string` ): First name.
    * `lastName` (`string` ): Last name.
    * `gender` (`string` ): Gender.
    * `nationality` (`string` ): Nationality.
    * `dateOfBirth` (`string` ): Date of birth.
    * `placeOfBirth` (`string` ): Place of birth.
    * `documentNumber` (`string` ): Document number.
    * `documentAdditionalNumber` (`string`): Additional document number.
    * `dateOfExpiry` (`string` ): Expiration date.
    * `dateOfIssue` (`string` ): Issue date.
    * `address` (`string` ): Address.
    * `city` (`string`): City.
    * `postalCode` (`string`): Postal code.
    * `documentType` (`string`): Document type (optional).
    * `barcodeType` (`string`): Barcode type (optional).
    * `rawData` (`Uint8Array`): Raw barcode data (optional).
    * `stringData` (`string`): Barcode text data (optional).
  * `barCodeExtractionDataBackDocument` (`object`): Back document barcode data (optional). Same structure as `barCodeExtractionDataFrontDocument`.
  * `tokenizedData` (`string`): Tokenized images (optional).
  * `iqaParameters` (`object`): Image quality parameters (optional).
    * `diagnostic` (`string`): IQA diagnostic.
    * `iqaOverExposure` (`number`): Overexposure.
    * `iqaUnderExposure` (`number`): Underexposure.
    * `iqaSharpness` (`number`): Sharpness.
    * `iqaReadability` (`number`): Readability.
    * `documentClass` (`string`): Document class.
    * `documentCaptured` (`string`): Captured document.
    * `ocrFields` (`number`): OCR fields detected.
    * `imgFields` (`number`): Image fields detected.
    * `morePagesAvailable` (`boolean`): Indicates whether more pages are available.
* `videoRecorded` (`Record<string, string>` | `null`): Video recording of the process, if applicable.
* `advancedTracking` (`Uint8Array` | `null`): Encoded advanced Tracking (optional).
* `ocrResult` (`OcrDetail`): Structured OCR result from the engine.
  * `version` (`number`): OCR format Version.
  * `type` (`string`): Detected document type.
  * `model` (`string`): OCR model used.
  * `ocr` (`object`): OCR field map (`{ [field]: { value, confidence?, source? } }`).
  * `images` (`OcrImage[]`): Images associated with the result.
  * `viz` (`OcrViz[]` ): Fields read from the visual zone.
  * `mrz` (`OcrMrz[]`): MRZ results (optional).
  * `encoded` (`OcrEncoded[]`): QR/barcode encoded data (optional). With [`codeReader`](https://docs.facephi.com/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/propiedades/codereader.md) active, the code read appears here (e.g. `{ type: 'qr', side: 1, raw: '...' }`), not in `result.images`.
  * `nfc` (`OcrNfc[]`): NFC data (optional).
  * `checks` (`object`): Consistency checks.
    * `field_inconsistency` (`FieldInconsistency[]`): Inconsistencies between sources.
* `coordinates` (`object` | `null`): User coordinates (`latitude`, `longitude` and `accuracy`). It is always present whenever [geolocation](https://docs.facephi.com/docs.facephi-en/sdks/sdk-web/componentes/sdk-provider/propiedades/geolocation.md) is not `DISABLED`, and is `null` when the location has not been obtained, either because permission was denied or because no response has been received yet. The request result, along with its reason, is reported in [geolocationFinish](https://docs.facephi.com/docs.facephi-en/sdks/sdk-web/componentes/sdk-provider/eventos/geolocationfinish.md). In TypeScript, `coordinates` is typed in `SelphidExtractionFinishDetail` from `@facephi/sdk-web-wc` and `@facephi/sdk-web-react`; the types in the `@facephi/selphid-web-component` package do not include it.

## Description

Contains the document data, images, and capture metadata.

### Considerations

The useful payload is in `event.detail.detail` (see [event format](https://docs.facephi.com/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/eventos.md#formato-de-los-eventos)).

Facephi recommends extracting OCR data from the backend using the front and back images (`result.images.frontDocument`, `result.images.backDocument`) rather than relying solely on `extractionData`.

## With [`codeReader`](https://docs.facephi.com/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/propiedades/codereader.md) in `optional`, this event may also be emitted without code data if the scan budget is exhausted.

## Example

```jsx
<facephi-selphid-widget
    onExtractionFinish={(event) => {
      const { result } = event.detail.detail;
      saveResults(result.images.frontDocument, result.images.backDocument);
    }}
/>
```

```typescript
import { type SelphidExtractionFinishDetail } from '@facephi/sdk-web-wc';

selphid.addEventListener('extractionFinish', (event) => {
  const detail: SelphidExtractionFinishDetail = event.detail.detail;
});
```
