-
Notifications
You must be signed in to change notification settings - Fork 1
/
PDF to Text Tests.py
63 lines (40 loc) · 1.13 KB
/
PDF to Text Tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# coding: utf-8
# In[11]:
#!pip install tika
# import parser object from tike
from tika import parser
# opening pdf file
parsed_pdf = parser.from_file("C:\\Users\\girlg\\Documents\\IT 496\\01323874.pdf")
# saving content of pdf
# you can also bring text only, by parsed_pdf['text']
# parsed_pdf['content'] returns string
data = parsed_pdf['content']
# Printing of content
print(data)
# <class 'str'>
print(type(data))
# In[ ]:
from tika import parser
import sys
import os
def convert_pdfs(path: str) -> bool:
parsed_pdf = parser.from_file(path)
data = parsed_pdf['content']
file = open(r'C:\Users\girlg\Downloads\Ravelry\pattern_text.txt', 'a', encoding="utf-8")
sys.stdout = file
print(data)
file.close()
convert_pdfs(r'C:\Users\girlg\IT496 -- Ravelry Project\00003472.pdf')
#cwd = os.getcwd()
#files = os.listdir(cwd)
#for i in files:
# try:
# result = convert_pdfs(i)
# print(result)
# except Exception as e:
# print('Exception in convert_pdfs():', e)
# In[ ]:
cwd = os.getcwd()
files = os.listdir(cwd)
print(files)