File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments