Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit a0a282b

Browse files
committed
add UI and fix issue PyPDF2.errors.DeprecationError: PdfFileReader is deprecated and was removed in PyPDF2 3.0.0. Use PdfReader instead.
1 parent 386016b commit a0a282b

5 files changed

Lines changed: 101 additions & 263 deletions

File tree

projects/pdf_to_text/README.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
1-
# PDF to TXT converter
2-
This script takes in a .pdf file and outputs a .txt file
1+
Certainly, here's an updated `readme.md` based on your provided code:
32

4-
### Requirements
5-
- Python
6-
- PyPDF2
3+
# PDF to Text Converter
74

5+
This Python script is designed to convert a PDF file into a plain text (.txt) file. It utilizes the PyPDF2 library for PDF parsing and the PyQt5 library for the graphical user interface. Follow the steps below to use this script effectively.
86

9-
### Steps
10-
In this program you have to provide the path for the pdf file that you want to convert into text and you may also provide the path where you want your output text file to be stored.
11-
By default the output files created will be stored in temp folder in the same directory.
7+
## Requirements
128

13-
## *Author Name*
14-
[pi1814](https://github.com/pi1814)
9+
- Python
10+
- PyPDF2
11+
- PyQt5
12+
13+
```bash
14+
pip install PyPDF2 PyQt5
15+
```
16+
17+
## Usage
18+
19+
1. **Run the Script**: Execute the Python script in your Python environment. Ensure you have the required libraries installed.
20+
21+
```bash
22+
python pdf_to_text.py
23+
```
24+
25+
2. **GUI Interface**: The script opens a graphical user interface (GUI) that simplifies the conversion process.
26+
27+
3. **Open PDF File**: Click the "Open PDF File" button, which prompts you to select the PDF file you want to convert. You can choose any PDF file from your local directory.
28+
29+
4. **Extract Text**: After selecting the PDF file, click the "Extract Text" button to initiate the conversion process. The script will extract the text from the PDF file and display it in the text box on the GUI.
30+
31+
5. **View Extracted Text**: The extracted text will be displayed in the text box on the GUI. You can read and review the text content.
32+
33+
## Author
34+
35+
- [pi1814](https://github.com/pi1814)
36+
37+
This script simplifies the process of converting PDF files to text. If you encounter any issues or have suggestions for improvements, please don't hesitate to reach out to the author on their GitHub page. Feel free to customize and use this script for your PDF to text conversion needs.

projects/pdf_to_text/converter1.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

projects/pdf_to_text/output.txt

Lines changed: 0 additions & 136 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import sys
2+
import os
3+
from PyPDF2 import PdfReader
4+
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QPushButton, QTextEdit, QVBoxLayout, QWidget
5+
6+
7+
class PDFTextExtractorApp(QMainWindow):
8+
def __init__(self):
9+
super().__init__()
10+
11+
12+
self.initUI()
13+
14+
def initUI(self):
15+
self.setGeometry(100, 100, 800, 600)
16+
self.setWindowTitle('PDF Text Extractor')
17+
18+
self.text_edit = QTextEdit(self)
19+
self.text_edit.setReadOnly(True)
20+
21+
self.btn_open_pdf = QPushButton('Open PDF File', self)
22+
self.btn_open_pdf.clicked.connect(self.openPDF)
23+
24+
self.btn_extract_text = QPushButton('Extract Text', self)
25+
self.btn_extract_text.clicked.connect(self.extractText)
26+
27+
layout = QVBoxLayout()
28+
layout.addWidget(self.text_edit)
29+
layout.addWidget(self.btn_open_pdf)
30+
layout.addWidget(self.btn_extract_text)
31+
32+
container = QWidget()
33+
container.setLayout(layout)
34+
self.setCentralWidget(container)
35+
36+
def openPDF(self):
37+
options = QFileDialog.Options()
38+
options |= QFileDialog.ReadOnly
39+
pdf_file, _ = QFileDialog.getOpenFileName(
40+
self, 'Open PDF File', '', 'PDF Files (*.pdf);;All Files (*)', options=options)
41+
if pdf_file:
42+
self.pdf_path = pdf_file
43+
44+
def extractText(self):
45+
if hasattr(self, 'pdf_path'):
46+
pdf_path = self.pdf_path
47+
text = self.extractTextFromPDF(pdf_path)
48+
self.text_edit.setPlainText(text)
49+
else:
50+
self.text_edit.setPlainText('No PDF file selected.')
51+
52+
def extractTextFromPDF(self, pdf_path):
53+
pdf_text = ''
54+
pdf_reader = PdfReader(pdf_path)
55+
for page in pdf_reader.pages:
56+
pdf_text += page.extract_text()
57+
return pdf_text
58+
59+
60+
def main():
61+
app = QApplication(sys.argv)
62+
window = PDFTextExtractorApp()
63+
window.show()
64+
sys.exit(app.exec_())
65+
66+
67+
if __name__ == '__main__':
68+
main()

projects/pdf_to_text/temp/samplePdf1.txt

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)