-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathconvert_pdf.py
35 lines (26 loc) · 984 Bytes
/
convert_pdf.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
import argparse
from pdftolatex.pdf import *
def convert(filepath):
"""Convert pdf at filepath to .tex file"""
if not os.path.isdir('localstore'):
os.mkdir('localstore')
if os.path.isdir(filepath):
for f in os.listdir(filepath):
convert(f)
filename = get_file_name(filepath)
pdf = PDF(filepath)
texfile = TexFile(pdf)
texfile.generate_tex_file(filename+".tex")
def main():
parser = argparse.ArgumentParser(description="Generate a .tex file from a .pdf file.")
parser.add_argument('--filepath', type=str, help="Path to pdf to be converted")
parser.add_argument('--folderpath', type=str, help="Path to folder containing pdfs to be converted. All pdfs in the folder will be converted")
args = parser.parse_args()
filepath = args.filepath
folderpath = args.folderpath
if folderpath:
convert(folderpath)
else:
convert(filepath)
if __name__ == "__main__":
main()