Skip to content

Commit fa13287

Browse files
authored
initial commit
1 parent 7102cd2 commit fa13287

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

markdown_to_pdf/markdown_to_pdf.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import markdown
2+
import pdfkit
3+
import sys
4+
import os
5+
6+
args = sys.argv[1:] # get command line *args
7+
assert args, "No file/dir was provided" # raise error is no arg is passed
8+
9+
print(args)
10+
11+
html_texts = []
12+
for arg in args:
13+
with open(arg, "r", encoding="utf-8") as input_file:
14+
text = input_file.read()
15+
16+
html_texts.append(markdown.markdown(text))
17+
18+
# configuring pdfkit to point to our installation of wkhtmltopdf
19+
config = pdfkit.configuration(
20+
wkhtmltopdf=r"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe")
21+
22+
for html_text in enumerate(html_texts):
23+
print(html_text[0])
24+
filename = args[html_text[0]].split('.')[0]
25+
pdfkit.from_string(html_text[1], f'{filename}.pdf', configuration=config)

0 commit comments

Comments
 (0)