-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Qredence/main
Merging
- Loading branch information
Showing
6 changed files
with
425 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
from PyPDF2 import PdfReader | ||
|
||
# Directory containing PDF files | ||
directory = 'graphfleet/input/pdf' | ||
|
||
# Function to convert PDF to text | ||
def convert_pdf_to_txt(pdf_path, txt_path): | ||
with open(pdf_path, 'rb') as pdf_file: | ||
reader = PdfReader(pdf_file) | ||
text = '' | ||
for page_num in range(len(reader.pages)): | ||
text += reader.pages[page_num].extract_text() | ||
with open(txt_path, 'w', encoding='utf-8') as txt_file: | ||
txt_file.write(text) | ||
|
||
# Loop through all PDF files in the directory | ||
for filename in os.listdir(directory): | ||
if filename.endswith('.pdf'): | ||
pdf_path = os.path.join(directory, filename) | ||
txt_path = os.path.join(directory, filename.replace('.pdf', '.txt')) | ||
convert_pdf_to_txt(pdf_path, txt_path) | ||
print(f'Converted {filename} to text.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.