{"id":23686370,"url":"https://github.com/lecodeurdudimanche/document-data-extractor","last_synced_at":"2026-01-09T01:30:14.899Z","repository":{"id":62516679,"uuid":"220298325","full_name":"LeCodeurDuDimanche/document-data-extractor","owner":"LeCodeurDuDimanche","description":"A simple library to extract data from documents with a known structure","archived":false,"fork":false,"pushed_at":"2019-11-16T21:18:44.000Z","size":183,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T21:32:15.436Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/lecodeurdudimanche/document-data-extractor","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LeCodeurDuDimanche.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-07T18:00:05.000Z","updated_at":"2019-11-16T21:19:07.000Z","dependencies_parsed_at":"2022-11-02T16:00:54.990Z","dependency_job_id":null,"html_url":"https://github.com/LeCodeurDuDimanche/document-data-extractor","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeCodeurDuDimanche%2Fdocument-data-extractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeCodeurDuDimanche%2Fdocument-data-extractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeCodeurDuDimanche%2Fdocument-data-extractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeCodeurDuDimanche%2Fdocument-data-extractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeCodeurDuDimanche","download_url":"https://codeload.github.com/LeCodeurDuDimanche/document-data-extractor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239742418,"owners_count":19689309,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-29T21:30:39.347Z","updated_at":"2026-01-09T01:30:14.857Z","avatar_url":"https://github.com/LeCodeurDuDimanche.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Document Data Extractor\nA simple PHP library to automate data extraction from documents with known formats.\n\n## Requirements\n\nThis library uses Tesseract to read text from documents and Imagick to manipulate the images.\n\nIt relies on GhostScript (`gs`) to convert pdf files to images.\n\n## Installation\n\nInstall required php libraries : `php-imagick`. On Ubuntu : \n```bash\napt install php7-imagick\n```\n\nThen install the package via composer :\n```bash\ncomposer require lecodeurdudimanche/document-data-extractor\n```\n\n## Usage\n\nFirst, you'll need to define what data you want to extract and where it is on the image :\n```php\n    $extractor = new Extractor();\n    $regionsOfInterest = [\n        // The name of the company is in the rectangle with the top left corner (700, 180) and a size of (1080, 160)\n        new ROI('Name of the company')-\u003esetRect(700, 180, 1080, 160),\n        new ROI('Total', 'integer')-\u003esetRect(1980, 1572, 58, 52);\n    ];\n```\nNext you can add some options forwarded to tesseract in order to get more precise results :\n```php\n    $tesseractConfiguration = [\n        'psm' =\u003e 8, // Page segmentation method is set to 8 (single word)\n        'tessdataDir' =\u003e '/usr/share/tessdata' // Other tesseract options ...\n    ];\n    $config = Configuration::fromArray(compact('regionsOfInterest', 'tesseractConfiguration'));\n    $extractor-\u003esetConfig($config);\n```\nThen you set the document you want to extract data from :\n```php\n    $extractor-\u003eloadImage('/path/to/image.png'); // or\n    $extractor-\u003eloadPDF('/path/to/document.pdf'); // or\n    $extractor-\u003esetImage($imageData); // could be an Imagick or GD image or raw image data\n```\nAnd finally you call the `run()` method to extract the data :\n```php\n    $data = $extractor-\u003erun();\n    /*\n    * $data = [\n    * ['label' =\u003e 'Name of the company', 'type' =\u003e 'text', 'data' =\u003e 'Company Limited'],\n    * ['label' =\u003e 'Total', 'type' =\u003e 'integer', 'data' =\u003e '55']\n    * ];\n    */\n```\n\nYou can save and load a `Configuration` object with the `toFile` and `fromFile` methods.\nThe file format is pretty formatted JSON.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecodeurdudimanche%2Fdocument-data-extractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flecodeurdudimanche%2Fdocument-data-extractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecodeurdudimanche%2Fdocument-data-extractor/lists"}