This is just a quick way to convert Markdown into pretty PDFs using macOS and Homebrew.
I created this as a more customizable solution to the homebrew md2pdf package, which has a horrible time with things like markdown tables.
You only need two packages installed to make this work:
brew install weasyprint
brew install pandocThis allows you to run a command in terminal like this:
pandoc filename.md -o filename.pdf --from=gfm --standalone --css=path/to/style.css --pdf-engine=weasyprintOK, so now that we can make PDFs easily, we can add some custom styles to make it pretty.
I have made the style.css CSS file you can use as a starter.
You can put it wherever you want, but I would recommend it go here:
$HOME/.config/md2pdf/style.cssNow, you can certainly use the full bash command example I provided above and call it a day, but why not make this a bit more helpful?
- Create a file
/usr/local/bin/md2pdf - Copy and Paste the content from md2pdf.sh into this new file
- Make that new file executable
sudo chmod +x /usr/local/bin/md2pdfNow you can do all sorts of fun stuff:
# Convert a single markdown file
md2pdf /path/to/file.md
md2pdf ./relative/file.md
# Convert all markdown files in folder
md2pdf /path/to/folder
# Convert all markdown files in folder and subfolders
md2pdf /path/to/folder --recursive