# Invoice to Excel Extractor (`yourname_mahi/invoice-to-excel-extractor`) Actor

Extracts vendor, dates, line items, subtotal, tax and total from uploaded invoice PDFs/images (OCR + regex/table parsing, no AI dependency) and pushes structured rows to the dataset, plus an Excel workbook per invoice.

- **URL**: https://apify.com/yourname\_mahi/invoice-to-excel-extractor.md
- **Developed by:** [MST MORIUM AKTHER MAYA](https://apify.com/yourname_mahi) (community)
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $50.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Invoice to Excel Extractor

Extracts structured data from invoices (PDF, PNG, JPG, JPEG, TIF, TIFF, BMP, WEBP) and turns each one into a clean Excel workbook — no AI/LLM dependency, so pricing and behavior stay predictable.

### What it extracts

- **Header fields:** vendor, invoice number, invoice date, subtotal, tax, total
- **Line items:** description, quantity, unit price, and line total (supports both classic 4-column tables and simpler description+amount rows)

Each field comes with a confidence score and a source (`native_text` for a PDF's real text layer, `ocr` for scanned/image invoices). A field is only ever filled in when there's direct evidence for it in the document — if OCR confidence is too low to trust, the field is left blank and flagged rather than guessed. This keeps the output honest: what you see is what the document actually says, not an AI's best guess.

### How it works

1. For PDFs with a real text layer, the native text and table structure are read directly (fast, high accuracy).
2. For scanned documents or images, Tesseract OCR extracts text with per-word confidence scores.
3. Regex and layout-aware rules pull out header fields and line items from the extracted text.
4. Results are written to the dataset (as structured JSON) and to a per-invoice Excel workbook (`.xlsx`) with a **Header** sheet and a **Line Items** sheet.

### Input

| Field | Description |
|---|---|
| **Invoice files** (required) | Upload files directly, or paste direct URLs to PDF/image files. |
| **Source storage** | Only needed if you uploaded files directly above — select that same key-value store so the Actor can read them. |
| **OCR language** | Tesseract language code for scanned pages (default: `eng`). |
| **OCR confidence threshold** | Minimum OCR word confidence (0–100) required to trust a value (default: `60`). |

### Output

One row per invoice in the dataset, plus an Excel file per invoice available for download via the `excel_url` field in that row. Each field/line item carries `value`, `source`, `confidence`, `flagged`, and `flag_reason` so you can see exactly how confident the extraction is and why anything was left blank.

### Known limitations

- Line-item and vendor extraction on scanned images depends on OCR quality; very low-resolution or heavily multi-column layouts can occasionally merge text from unrelated parts of the page.
- Date parsing does not attempt to disambiguate DD/MM vs. MM/DD formats — an ambiguous date is left blank rather than guessed.

# Actor input Schema

## `invoiceFiles` (type: `array`):

Invoice files to extract (PDF, PNG, JPG, JPEG, TIF, TIFF, BMP, WEBP). Upload files directly - each becomes a URL automatically - or paste direct URLs to files.

## `sourceStores` (type: `array`):

Only needed if you uploaded files directly in the field above (not needed for pasted external URLs): select that same key-value store here so the Actor is granted access to read the uploaded files from it.

## `language` (type: `string`):

Tesseract language code used for pages/images with no extractable text layer.

## `confidenceThreshold` (type: `integer`):

Minimum mean OCR word confidence (0-100) required to trust a field. Below this, the field is left blank and flagged rather than guessed.

## Actor input object example

```json
{
  "invoiceFiles": [],
  "language": "eng",
  "confidenceThreshold": 60
}
```

# Actor output Schema

## `invoices` (type: `string`):

Structured invoice data extracted per input file - one row per file, in the Actor's default dataset.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "invoiceFiles": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("yourname_mahi/invoice-to-excel-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "invoiceFiles": [] }

# Run the Actor and wait for it to finish
run = client.actor("yourname_mahi/invoice-to-excel-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "invoiceFiles": []
}' |
apify call yourname_mahi/invoice-to-excel-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,yourname_mahi/invoice-to-excel-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/dMJLxIczrw75UH9rW/builds/PEhP72IGoqy5rhr2E/openapi.json
