<jupyter_start><jupyter_text>This simple tutorial shows how to convert a folder with PDF files into a folder with Text files using Apache Tika (see https://tika.apache.org/).<jupyter_code>from tika import parser
import os
import re

pdfdir = 'data/pdf'
txtdir = 'data/txt'

for subdir, dirs, files in os.walk(pdfdir):
    for file in files:
        if file.endswith('.pdf'):
            pdf = parser.from_file(pdfdir + '/' + file)
            txtfile = re.sub('.pdf', '.txt', file)
            fout = open(txtdir + '/' + txtfile, 'w', encoding='utf-8')
            print(pdf['content'], file=fout)
            fout.close()
print('done')<jupyter_output>done
{'fraction_non_alphanumeric': 0.13871951219512196, 'fraction_numerical': 0.001524390243902439, 'mean_word_length': 2.9578313253012047, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '302836', 'license': 'Apache-2.0', 'n_tokens_mistral': 217, 'n_tokens_neox': 215, 'n_words': 62, 'path': 'PDF2TXT.ipynb', 'repo_name': 'averbis/jupyter-tutorials', 'size': '656'}