File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Markdown to pdf
2
+
3
+ Convert markdown file or files to pdfs
4
+
5
+ ## Setup instructions
6
+ ```
7
+ python -r requirements.txt
8
+ ```
9
+ - call the script and pass the name or names of the markdown files
10
+ ```
11
+ python markdown_to_pdf.py sample1.md sample2.md sample3.md
12
+ ```
13
+ ## Output
14
+
15
+ will create equivalent pdf files of the markdown files
16
+
17
+ ## Author
18
+ [ JPPhilips] ( https://www.github.com/jpphilips )
19
+
20
+
21
+ ## Disclaimers, if any
22
+
23
+ if not installed, need to:
24
+ - download and install wkhtmltopdf
25
+ - Set download folder path in PATH Environment variables.
Original file line number Diff line number Diff line change
1
+ import markdown
2
+ import pdfkit
3
+ import sys
4
+
5
+ args = sys .argv [1 :] # get command line *args
6
+ assert args , "No file/dir was provided" # raise error is no arg is passed
7
+
8
+ print (args )
9
+
10
+ html_texts = []
11
+ for arg in args :
12
+ with open (arg , "r" , encoding = "utf-8" ) as input_file :
13
+ text = input_file .read ()
14
+
15
+ html_texts .append (markdown .markdown (text ))
16
+
17
+ # configuring pdfkit to point to our installation of wkhtmltopdf
18
+ config = pdfkit .configuration (
19
+ wkhtmltopdf = r"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe" )
20
+
21
+ for html_text in enumerate (html_texts ):
22
+ print (html_text [0 ])
23
+ filename = args [html_text [0 ]].split ('.' )[0 ]
24
+ pdfkit .from_string (html_text [1 ], f'{ filename } .pdf' , configuration = config )
Original file line number Diff line number Diff line change
1
+ Markdown == 3.4.1
2
+ pdfkit == 1.0.0
You can’t perform that action at this time.
0 commit comments