|
import os |
|
import subprocess |
|
from tqdm import tqdm |
|
|
|
|
|
pdfs_folder = "pdfs" |
|
texts_folder = "texts3" |
|
ocr_pdfs_folder = "ocr_d_pdfs" |
|
|
|
|
|
if not os.path.exists(texts_folder): |
|
os.makedirs(texts_folder) |
|
|
|
if not os.path.exists(ocr_pdfs_folder): |
|
os.makedirs(ocr_pdfs_folder) |
|
|
|
|
|
for filename in tqdm(os.listdir(pdfs_folder)): |
|
if filename.endswith(".pdf"): |
|
pdf_path = os.path.join(pdfs_folder, filename) |
|
text_filename = filename.replace(".pdf", ".txt") |
|
output_pdf = os.path.join(ocr_pdfs_folder, filename) |
|
text_path = os.path.join(texts_folder, text_filename) |
|
|
|
|
|
subprocess.run(["ocrmypdf", pdf_path, output_pdf, "--sidecar", text_path, "--force-ocr"]) |
|
|