0%

Convert markdown file to PDF file

I keep my resume on github, and is going to update it with my working experience changing.Since resume is written in markdown format on github, I need a PDF format when applying job on line. How to convert markdown file to PDF file easily?

Convert markdown file to html format first

You need to check markdown is already installed or not. If not, you need use apt install markdown to install it.

1
2
anna@ubuntu1804:~$ which markdown
/usr/bin/markdown

Go to directory where your markdown file lies, run

1
anna@ubuntu1804:~/git_repo/resume$ markdown resume.md resume.html

you will convert resume.md markdown file to resume.html

then you can go to webbrowser to see this html file, to make sure it works.

Convert html file to PDF file

To convert PDF file, you need to use wkhtmltopdf tool

1
2
3
apt install wkhtmltopdf
anna@ubuntu1804:~$ which wkhtmltopdf
/usr/bin/wkhtmltopdf

go to the same directory where the resume.md and resume.html lie, run

1
wkhtmltopdf -s letter  -B 25mm -T 25mm -L 25mm -R 25mm resume.html resume.pdf

then you can get the PDF format resume file.

1
2
3
4
anna@ubuntu1804:~/git_repo/resume$ ll
-rw-r--r-- 1 anna anna 4493 Oct 14 22:46 resume.html
-rw-r--r-- 1 anna anna 3728 Oct 14 22:45 resume.md
-rw-r--r-- 1 anna anna 34985 Oct 14 22:46 resume.pdf

Write a script to execute convert automaticly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#/bin/bash

md=$1

# validate md
if [ ! -f "$md" ]; then
echo "Usage: $0 <markdown file name>"
exit 1
fi

html="${md%%.*}.html"

pdf="${md%%.*}.pdf"

markdown $md > $html

wkhtmltopdf -s letter -B 25mm -T 25mm -L 25mm -R 25mm $html $pdf

after you update resume, you can run md2pdf.sh, then get the PDF file automaticlly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
anna@ubuntu1804:~/git_repo/resume$ ./md2pdf.sh resume.md
Loading page (1/2)
Printing pages (2/2)
Done
anna@ubuntu1804:~/git_repo/resume$ ll
total 76
drwxr-xr-x 3 anna anna 4096 Oct 15 00:17 ./
drwxr-xr-x 3 anna anna 4096 Oct 14 21:38 ../
drwxr-xr-x 8 anna anna 4096 Oct 15 00:09 .git/
-rw-r--r-- 1 anna anna 12 Oct 14 22:48 .gitignore
-rwxr-xr-x 1 anna anna 268 Oct 14 22:36 md2pdf.sh*
-rw-r--r-- 1 anna anna 17 Oct 14 21:38 README.md
-rw-r--r-- 1 anna anna 4774 Oct 15 00:18 resume.html
-rw-r--r-- 1 anna anna 3974 Oct 15 00:17 resume.md
-rw-r--r-- 1 anna anna 36063 Oct 15 00:18 resume.pdf
-rw-r--r-- 1 anna anna 280 Oct 14 21:38 support.md