Gangmax Blog

Convert markdown to PDF using Node.js

Solution one is markdown-pdf.

Install the “markdown-pdf” npm module.

Then run the following code in node.js:

1
2
3
4
5
6
var markdownpdf = require("markdown-pdf");
markdownpdf()
.from("/home/auser/test.markdown")
.to("/home/auser/test.pdf", function () {
console.log("Done")
})

Solution two I found(added on 2017-10-26) which is better: mdpdf.

1
2
3
4
5
6
7
8
# 1. Install "mdpdf" npm package(from: https://www.npmjs.com/package/mdpdf):
npm install mdpdf
# 2. Go the the directory of the installed "mdpdf" npm package:
cd ~/node_modules/mdpdf
# 3. Run the following command:
bin/index.js ~/palantir.md
✨ PDF created successfully at: /home/auser/palantir.pdf
# The output shows the PDF file is created successfully.

Comments