<jupyter_start><jupyter_text>Extracting PDF Information (size, pages, outline)<jupyter_code>import PyPDF2 as p2
import os
import pandas as pd
%%time
#get PDF size attributes
# folder = 'F:/Environmental Baseline Data/Version 4 - Final/PDF' # old projects
folder = 'G:/ESA_downloads/phase_2_download_files/PDFs' # new projects
files_in_folder = os.listdir(folder)
files_in_folder_path = [folder +  '/' + str(x) for x in files_in_folder]
print('number of files in folder: ' + str(len(files_in_folder_path)))
exceptions = []
dict_data = []

for x in files_in_folder_path:
    try:
        PDFfile = open(x, 'rb')
        pdfread = p2.PdfFileReader(PDFfile)
        page_count = pdfread.getNumPages()
        size_bytes = os.path.getsize(x)
        MB = round(size_bytes/1048576.7009, 2)
        outline_boolean = p2.PdfFileReader(PDFfile)
        outline = pdfread.getOutlines(PDFfile)
        if not outline:
            outline_boolean = 'No'
        else:
            outline_boolean = 'Yes'
        dict_line = {'file_name' : x, 'page_count' : page_count, 'size (MB)' : MB, 
                     'Contains outline?': outline_boolean}
        dict_data.append(dict_line)
    except:
        pass
        exceptions.append(x)
        
df_size = pd.DataFrame(dict_data)
df_size.head()
df_size.to_csv('PDF-size-numpages-outlineboolean-new-projects.csv')
df_size.to_excel('PDF-size-numpages-outlineboolean-new-projects.xlsx')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11371467953135768, 'fraction_numerical': 0.012405237767057202, 'mean_word_length': 3.3603603603603602, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '138299', 'license': 'MIT', 'n_tokens_mistral': 511, 'n_tokens_neox': 500, 'n_words': 98, 'path': 'berdi/Section_05_VEC_Labeling_for_Tables/PDF-size-numpages-outlineboolean.ipynb', 'repo_name': 'iVibudh/CER-ESA-Phase2', 'size': '1451'}