-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpdf2md.py
More file actions
51 lines (38 loc) · 969 Bytes
/
pdf2md.py
File metadata and controls
51 lines (38 loc) · 969 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -------------------------
# (c) kelu124
# cc-by-sa/4.0/
# -------------------------
from bs4 import BeautifulSoup
import re
import os
import urllib2
import html2text
from lxml import etree
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import pyPdf
Messages = []
for root, directories, filenames in os.walk('./'):
for directory in directories:
print os.path.join(root, directory)
for filename in filenames:
print os.path.join(root,filename)
if (".pdf" in filename) and ("pdf-raw" in root):
Messages.append(os.path.join(root,filename) )
for item in Messages:
MessageBC2 = ""
info = item.split("/")
print info
#print fileset
filename = info[-1].split(".")[0]
#print filename
SaveFile = "./pdf-data/"+filename+".md"
pdf = pyPdf.PdfFileReader(open(item, "rb"))
for page in pdf.pages:
PDFTxt = page.extractText()
file = open(SaveFile, 'w')
file.write(PDFTxt)
file.close()