-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo.py
More file actions
59 lines (47 loc) · 1.88 KB
/
go.py
File metadata and controls
59 lines (47 loc) · 1.88 KB
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
from pdfminer.high_level import extract_text
from fpdf import FPDF
import re
def main():
positionName = ""
companyName = ""
companyValue = "" # Do not include period at the end of sentence
companyAddress = ""
industry = "Technology"
hiringManager = "Hiring Manager"
name = "Samarth Verma"
email = "samarthverma1108@gmail.com"
number = "(732)-500-7690"
templatePath = "/Users/samarthVerma/Documents/Cover Letter/CL_TEMPLATE_3.pdf"
outputPath = f"/Users/samarthVerma/Documents/Cover Letter/Companies/{companyName}_CoverLetter.pdf"
my_vars = {
"[Position Name]": positionName,
"[Company Name]": companyName,
"[Specific Company Value]": companyValue,
"[Company Address]": "\n" + companyAddress,
"[Industry/Field]": industry,
"[Hiring Manager]": "" + hiringManager + "\n",
"[myName]" : "\n" + name,
"[myEmail]" : "\n" + email,
"[myNumber]" : "\n" + number,
}
text = extract_text(templatePath, page_numbers=[0])
for placeholder, value in my_vars.items():
text = text.replace(placeholder, value)
# Clean up the text: remove unnecessary newlines within paragraphs but preserve paragraph breaks
text = re.sub(r'\n{2,}', '\n\n', text) # Keep double newlines as paragraph breaks
text = re.sub(r'(?<!\n)\n(?!\n)', ' ', text) # Replace single newlines with spaces
# Add a newline before each dash followed by a space
text = re.sub(r'(?<!\n)- ', '\n- ', text)
pdf = FPDF('P', 'pt', 'Letter')
pdf.add_page()
pdf.set_margins(72, 72, 72)
pdf.ln(30)
pdf.set_font("Arial", size=10)
paragraphs = text.split('\n\n')
for paragraph in paragraphs:
pdf.multi_cell(0, 12, txt=paragraph)
pdf.ln(10)
pdf.output(outputPath)
print(f"PDF has been created and saved to {outputPath}")
if __name__ == "__main__":
main()