I am a big fan of markdown language for writing documents. One of the scenarios we encounter using markdown is to generate a pdf file or convert the markdown files to some other format. This post is to introduce an NPM package that converts markdown files to pdf file. It is considerably old but still does the job.
markdown-pdf
markdown-pdf npm library is open source software with MIT license. They have just enough documentation as well. It can be used as a command and as a library to use from our nodejs applications.
The limitations I found are as follows.
There is no direct API to convert an entire folder of markdown (.md) files. We have to iterate the folder by ourselves and give it all the file paths. Another problem is to insert page breaks between the markdown files. But that also can be overcome by using pre-processing markdown interceptor and some css tricks.
Sample code
- How a folder can be given to markdown-pdf as there is no direct API
- How to preprocess markdown files
- How to give a custom CSS file
How it works
Use cases
Other libraries
- md-to-pdf - This uses Marked library to convert .md files to HTML. Then Puppeteer to print pdf. It also supports code highlighting via highlight.js library.
- There is a node-pandoc library that tells, it converts to pdf using pandoc. This method is not tried.
No comments:
Post a Comment