> 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

## Details

Emitted when document extraction is completed with all expected data.

**Event:** `extractionFinish`

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

### 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 in the extraction (optional).
  * `diagnostic` (`number`): Extraction diagnostic code.
  * `detectionStatus` (`object`): Detected document status.
    * `status` (`number`): Extraction status.
    * `quad` (`object`): Document position in the frame (optional).
      * `topLeft` (`{ x, y }`): Upper-left corner.
      * `topRight` (`{ x, y }`): Upper-right corner.
      * `bottomLeft` (`{ x, y }`): Lower-left corner.
      * `bottomRight` (`{ x, y }`): Lower-right corner.
    * `glare` (`boolean`): Glare detected on the document (optional).
    * `internalStatus` (`object`): Internal engine status.
      * `standard` (`number`): Standard status code.
  * `extractionData` (`object`): Structured OCR fields.
    * `firstName` (`string`): First name.
    * `lastName` (`string`): Surnames.
    * `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`): Expiry 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 debug 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`): Surnames.
      * `documentId` (`string`): Document identifier.
      * `documentNumber` (`string`): Document number.
      * `documentIssuer` (`string`): Document issuer.
      * `dateOfExpiry` (`string`): Expiry date.
      * `dateOfBirth` (`string`): Date of birth.
      * `gender` (`string`): Gender.
      * `nationality` (`string`): Nationality.
    * `ocr` (`object`): OCR data.
      * `firstName` (`string`): First name.
      * `lastName` (`string`): Surnames.
      * `fullName` (`string`): Full name (optional).
      * `documentId` (`string`): Document identifier.
      * `documentNumber` (`string`): Document number.
      * `dateOfBirth` (`string`): Date of birth.
      * `dateOfExpiry` (`string`): Expiry date.
      * `dateOfIssue` (`string`): Issue date.
      * `gender` (`string`): Gender.
      * `nationality` (`string`): Nationality.
  * `images` (`object`): Cropped document images.
    * `frontDocument` (`string` | `null` | `undefined`): Front side.
    * `backDocument` (`string` | `null` | `undefined`): Back side.
    * `faceImage` (`string` | `null` | `undefined`): Face on the document.
    * `signatureImage` (`string` | `null` | `undefined`): Signature.
  * `imagesFullsize` (`object`): Full-size images.
    * `frontDocument` (`string` | `null` | `undefined`): Complete front side.
    * `backDocument` (`string` | `null` | `undefined`): Complete back side.
  * `imagesRaw` (`object`): Raw images (`ImageData`).
    * `frontDocument` (`ImageData` | `null` | `undefined`): Raw front side.
    * `backDocument` (`ImageData` | `null` | `undefined`): Raw back side.
    * `faceImage` (`ImageData` | `null` | `undefined`): Raw face.
    * `signatureImage` (`ImageData` | `null` | `undefined`): Raw signature.
  * `barCodeExtractionDataFrontDocument` (`object`): Front barcode data (optional).
    * `firstName` (`string`): First name.
    * `lastName` (`string`): Surnames.
    * `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`): Expiry 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 code data (optional).
    * `stringData` (`string`): Text code data (optional).
  * `barCodeExtractionDataBackDocument` (`object`): Back 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`): Document captured.
    * `ocrFields` (`number`): Detected OCR fields.
    * `imgFields` (`number`): Detected image fields.
    * `morePagesAvailable` (`boolean`): Indicates whether more pages are available.
* `videoRecorded` (`Record<string, string>` | `null`): Recorded video of the process, if applicable.
* `advancedTracking` (`Uint8Array` | `null`): Encoded advanced Tracking (optional).
* `ocrResult` (`OcrDetail`): Structured OCR result from the engine.
  * `version` (`number`): Version of the OCR format.
  * `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 area.
  * `mrz` (`OcrMrz[]`): MRZ results (optional).
  * `encoded` (`OcrEncoded[]`): Encoded QR/barcode/PDF data (optional).
  * `nfc` (`OcrNfc[]`): NFC data (optional).
  * `checks` (`object`): Consistency checks.
    * `field_inconsistency` (`FieldInconsistency[]`): Inconsistencies between sources.

## Description

Contains the document data, images, and capture metadata.

### Considerations

The useful payload is in `event.detail.detail` (see [event format](/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`) instead of relying solely on `extractionData`.

***

## 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;
});
```
