Skip to content

Commit

Permalink
feat: add pdf to png conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
cybardev committed Jan 18, 2024
1 parent 44fee95 commit 1663992
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/resume/components/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class Resume:
def __init__(self, author):
self.author = author

def build(self, filename: str, output_dir: str):
with open(output_dir + filename, "w") as file:
def build(self, filename: str):
with open(filename, "w") as file:
file.write(str(self))

def __str__(self) -> str:
Expand Down
32 changes: 22 additions & 10 deletions src/resume/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ def xp_fmt(name: str, address: str, spec: str, date: str) -> str:


def md_to_pdf(
md_file: str,
pdf_file: str,
filename: str,
html_template: str = "./src/template/resume.html",
css_template: str = "./src/template/resume.css",
) -> None:
subprocess.run(
[
"pandoc",
md_file,
f"{filename}.md",
"-t",
"html",
f"--template={html_template}",
Expand All @@ -43,18 +42,31 @@ def md_to_pdf(
"margin-left=0",
"--pdf-engine-opt=--enable-local-file-access",
"-o",
pdf_file,
f"{filename}.pdf",
]
)


def pdf_to_png(
filename: str,
) -> None:
subprocess.run(
["pdftoppm", "-png", "-singlefile", f"{filename}.pdf", filename]
)


def generate_resume(author, output_dir: str) -> Resume:
# generate resume and output to file and standard output
# generate resume and output to markdown file
resume: Resume = Resume(author)
filename = f"Resume_{resume.author.name.replace(' ', '_')}"
resume.build(f"{filename}.md", output_dir)
md_to_pdf(
f"{output_dir.rstrip('/')}/{filename}.md",
f"{output_dir.rstrip('/')}/{filename}.pdf",
filename = (
output_dir.rstrip("/")
+ "/"
+ f"Resume_{resume.author.name.replace(' ', '_')}"
)
resume.build(f"{filename}.md")

# convert markdown to pdf and generate png image
md_to_pdf(filename)
pdf_to_png(filename)

return resume

0 comments on commit 1663992

Please sign in to comment.