{"id":21740552,"url":"https://github.com/writecrow/ocr2text","last_synced_at":"2025-08-21T18:33:15.175Z","repository":{"id":37497489,"uuid":"213093487","full_name":"writecrow/ocr2text","owner":"writecrow","description":"Convert a PDF via OCR to a TXT file in UTF-8 encoding","archived":false,"fork":false,"pushed_at":"2023-10-03T21:34:47.000Z","size":59,"stargazers_count":141,"open_issues_count":6,"forks_count":30,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-12-10T04:32:39.437Z","etag":null,"topics":["batch","converter","corpus","ocr","pdf","tesseract"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/writecrow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-06T01:27:02.000Z","updated_at":"2024-10-25T10:34:41.000Z","dependencies_parsed_at":"2022-07-17T00:00:41.288Z","dependency_job_id":null,"html_url":"https://github.com/writecrow/ocr2text","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writecrow%2Focr2text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writecrow%2Focr2text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writecrow%2Focr2text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writecrow%2Focr2text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/writecrow","download_url":"https://codeload.github.com/writecrow/ocr2text/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230527866,"owners_count":18240051,"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":["batch","converter","corpus","ocr","pdf","tesseract"],"created_at":"2024-11-26T06:13:59.209Z","updated_at":"2024-12-20T03:09:29.494Z","avatar_url":"https://github.com/writecrow.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PDF to TXT (with OCR)\nGiven one or more PDFs that may include text-as-image content, use OCR (Optical Character Recognition) to convert the content to TXT files (in UTF-8 encoding).\n\n## Rationale\nA survey of existing PDF-to-TXT solutions found no extant solutions that meet all of the following criteria:\n- is an offline tool (to keep secure human-subject information)\n- provides conversion from PDF to TXT (most existing OCR integrations assume an image as input)\n- supports batch processing of multiple files\n\n## Assumptions\n- This is (currently) a command-line tool, written in Python. Basic familiarity with executing commands in a terminal, as well as directory structure, is assumed. \n- It is assumed that you have Python version 3.x installed, as well as [Pip](https://pypi.org/project/pip/).\n- This script relies on an industry-standard OCR library managed by Google, called [Tesseract](https://github.com/tesseract-ocr/tesseract). Since it is written in C++, for Python to be able to use it, it needs to be installed separately (instructions below). Similarly, a PDF-to-image library, [Poppler](https://gitlab.freedesktop.org/poppler/poppler), will need to be installed on Windows and Mac systems.\n\n## Setup\n- [Windows](##windows)\n- [MacOS](##macos)\n- [Linux](##linux)\n\n## Windows\n\n1. Make a new folder on your Desktop called `ocr` (e.g., `C:\\Users\\mark\\Desktop\\ocr`)\n2. Download and install the Tesseract 4 OCR library from [Tesseract at UB Mannheim](https://github.com/UB-Mannheim/tesseract/wiki)\n2. The installation should indicate which directory Tesseract-OCR was installed. Most likely, this will either be `C:\\Program Files (x86)\\Tesseract-OCR` or `C:\\Program Files\\Tesseract-OCR`. **Move this folder into your equivalent of `C:\\Users\\mark\\Desktop\\ocr`, so that it is now located at `Desktop\\ocr\\Tesseract-OCR`.**\n3. Download [poppler for Windows](http://blog.alivate.com.au/poppler-windows/). \n4. You may need to install [7Zip](https://www.7-zip.org/) to unzip the executable, as well.\n5. Place the unzipped files in `Desktop\\ocr\\poppler-0.68.0_x86`).\n6. From your start menu, navigate to **Control Panel** \u003e **System and Security** \u003e **System** \u003e **Advanced System Settings**\n7. Then click **Environment Variables**.\n8. In the **System Variables** window, highlight **Path**, and click **Edit**.\n9. Click **New** to add an additional path.\n10. Paste the full path to the location of Tesseract (e.g., `C:\\Users\\mark\\Desktop\\\\ocr\\Tesseract-OCR`) and press **OK**.\n11. Again, click **New** to add an additional path.\n12. Paste your equivalent of `C:\\Users\\mark\\Desktop\\ocr\\poppler-0.68.0_x86\\poppler-0.68.0\\bin` and press **OK**.\n13. Press **OK** on any remaining control panel windows.\n14. Download [OCR2Text](https://github.com/writecrow/ocr2text/archive/master.zip) to `Desktop\\ocr`).\n15. Unzip the project.\n16. Open a `cmd.exe` terminal, and navigate to the folder via the command line (e.g., `cd Desktop\\ocr\\ocr2text-master`)\n17. Run `pip install --user --requirement requirements.txt`\n18. Optionally, you can check that you set up the PATH variable correctly in steps 6-10 by typing `echo %PATH%`. The output must include your equivalent of `C:\\Users\\mark\\Desktop\\ocr\\Tesseract-OCR` and `C:\\Users\\mark\\Desktop\\ocr\\poppler-0.68.0_x86\\poppler-0.68.0\\bin` for the script to work.\n\n\n## macOS\n1. Make a new folder on your Desktop called `ocr` (i.e., `/Users/mark/Desktop/ocr`)\n2. Install Tesseract-OCR using either MacPorts (`sudo port install tesseract`) or Homebrew (`brew install tesseract`\n3. Install [poppler for Mac](http://macappstore.org/poppler/).\n4. Download this Github project to `/Users/mark/Desktop/ocr`).\n5. Unzip the project.\n6. Open a terminal and navigate to the folder via the command line (e.g., `cd /Users/mark/Desktop/ocr/ocr2text`)\n7. Run `pip install --user --requirement requirements.txt`\n\n## Linux\n1. `sudo apt-get install tesseract-ocr`\n2. Most distros ship with `pdftoppm` and `pdftocairo`. If they are not installed, refer to your package manager to install `poppler-utils`\n4. Download this Github project.\n5. Unzip the project.\n6. Open a terminal and navigate to the folder\n7. Run `pip install --user --requirement requirements.txt`\n\n## Usage\nIf you have successfully completed the setup steps and are using Python version 3, usage should now be a breeze:\n\nOn the command line, navigate to the directory where you downloaded the script and run:\n\n```\npython ocr2text.py\n```\n\nYou will see the following:\n\n```\n********************************\n*** PDF to TXT file, via OCR ***\n********************************\n\nIndicate file or folder of source PDF(s) []:\n(Press [Enter] for current working directory)\n\n```\n\nEnter the full path to the file or directory to convert.\n\n```\nDestination folder for TXT []:\n(Press [Enter] for current working directory)\n```\n\nEnter the full path to the directory where the result file(s) should be outputted.\n\nThe script will now covert the PDF via OCR into a plaintext file:\n\n### Testing the installation\nFor testing purposes, a `test_files` directory is included. You can press [Enter] for the source and destination directories \u0026 verify that the `image.pdf` file is converted. It will also be located in the `test_files` directory:\n\n```\nConverted C:\\Users\\mark\\ocr2text\\image.pdf\nPercent: [##########] 100%\n1 file converted\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritecrow%2Focr2text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwritecrow%2Focr2text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritecrow%2Focr2text/lists"}