A repository for handling virtually all types unstructured text documents and converting them into docx or pdfs. Essentially parses through several nested folders (zipped or otherwise) to access all the text files and convert them to pdf. Used for the Department of Organization Studies.
- Automatic Zip Extraction
- Handles top-level and nested ZIP archives.
- Combining Different Formats
- Merge DOC (1997-2003), DOCX, RTF, ODT, PDF, and TXT files together seamlessly.
- Large File Splitting
- Splits final PDFs if page counts exceed a chosen threshold, to keep them more manageable.
- Ignore Irrelevant Folders and Corrupt Files
- Skips merging text from specified folders (e.g.,
literature,__MACOSX) and skips merging corrupt docx/pdf files.
- Skips merging text from specified folders (e.g.,
Assuming you already have the repository and the environment on your computer, you need to do the following:
- Open Windows command window and navigate to your project folder using
cd path/to/projectand:
git pull
- Activate and sync the environment
.venv\Scripts\activate
uv pip sync requirements.txt
Make sure you have a suitable version of Python 3.x installed.
Any version after 3.6 recommended.
uv is a python dependency manager. To install it, open the Windows Powershell command window on your windows machine using the search option in your task bar. Inside the powershell window, paste the following line:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
If you do not have Git installed, follow these steps:
- Windows: Download and run the installer from git-scm.com.
Go to this link and download libre office. Please make sure you are installing it in the C drive. The standard location is C:\Program Files\LibreOffice.
Note: If you are choosing to download it elsewhere (or it happens to be located elsewhere), please locate the path of the soffice.exe file. It is located inside the LibreOffice\program folder. Once you have located the soffice.exe file, please replace the DEFAULT_SOFFICE variable at the top of the conversion_utils.py script.
Go to a desired folder location in your PC and open git bash. This can be done by right clicking and selecting open git bash here.
git clone https://gitlab.uvt.nl/tsb-rst/universal_text_conversion.gitYou can now close the git bash terminal.
Next, open the windows terminal (search for Command Prompt) from the start menu and navigate to your project folder chosen in step 1. Then, we can create uv environment. This step will use the requirements.txt file and also install all the dependences. This can be done using the code segments below.
- Navigating to your project folder
cd path/to/your/project/folder
- Making a uv environment.
Initializing the environment and downloading the dependencies
uv sync
Activating the environment (This is done every time you wish to run the script!)
.venv\Scripts\activate
- To run the merging script, first activate your environment (if you haven't already) and then write the code below in the windows terminal. The repository comes with a
dummy_input_folderthat contains text files with various formats. After the step below, you will see your merged pdf in the output folder!
python -m merge_files
The script will automatically check whether or not an output folder has been created, and if so, skips to the next folder. This comes handy and saves time when you have add new input folders.
The python library tqdm was used to add a progress bar while the text files are merged.
-
If you have extremely large PDFs generated, the script will automatically split them to keep file sizes manageable.
-
The default number of pages is set to
1000for a part if the pdf has to be split. You can change this parameter in the_finalize_pdffunction inconversion_utils.pyscript.
And you're all set!
For any questions, please contact s.narayanan@tilburguniversity.edu
