File size: 1,021 Bytes
ba6ea70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import PyPDF2
from jinja2 import FileSystemLoader, Environment


def parse_pdf(pdf_file):
    if pdf_file is isinstance(pdf_file, str):
        with open(pdf_file, "rb") as file:
            return _parse(file)
    else:
        return _parse(pdf_file)


def _parse(file):
    reader = PyPDF2.PdfReader(file)
    pdf_text = []
    num_pages = len(reader.pages)
    # Iterate over each page
    for page_number in range(num_pages):
        # Get the current page
        page = reader.pages[page_number]

        # Extract the text from the page
        page_text = page.extract_text()

        pdf_text.append(page_text)
    pdf_text = '\n'.join(pdf_text)
    return pdf_text, num_pages


def build_html_resume(data):
    env = Environment(loader=FileSystemLoader('src/templates'))
    template = env.get_template('resume.html')
    html_resume = template.render(data)
    return html_resume


def export_html(html_resume, output_path):
    with open(output_path, 'w', encoding='utf8') as f:
        f.write(html_resume)