I need to convert the GitHub README.md file to pdf. I tried many modules, those are not working fine. Is there any new tool to get the exact pdf format. In this website is providing good conversion format of pdf. http://www.markdowntopdf.com/ I need command line tool like this format.
-
2Since Stack Overflow hides the Close reason from you: Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.– jwwCommented Feb 16, 2018 at 7:42
-
Or maybe Software Recommendations Stack Exchange would be a better place to ask.– jwwCommented Feb 16, 2018 at 7:43
3 Answers
Pandoc
I've personally liked using pandoc as it support a wide range of input and output formats.
Installation
Pandoc is available in most repositories: sudo apt install pandoc
Usage
Sometimes, pandoc can tell the formats to use which makes converting easy. However, I find that this often interprets the input format as plain text which might not be what you want:
pandoc README.md -o README.pdf
Instead, you might want to be explicit about the input/output formats to ensure a better conversion. In the below case, I'm specifically claiming the README.md is in Github-Flavored Markdown:
pandoc --from=gfm --to=pdf -o README.pdf README.md
Again, there are quite a few different formats and options to choose from but to be honest, the basics suffice for the majority of my needs.
-
pandoc does not seem to process <img> tags. okular will read md files and on export does produce pdf with images Commented Jun 5, 2023 at 15:22
-
5if one want to spend a hour fighting unicode/font problems, pandoc is a perfect choice Commented Sep 14, 2023 at 12:38
-
Thank you for providing the commands to use. To add on, I had to stylize my code blocks, so I used this command:
pandoc -V geometry:margin=1in --highlight-style=zenburn --from=gfm --to=pdf -o README.pdf README.md
. I am not sure if the margin was needed for my case, but I used that flag anyways. I was able to obtain the light of highlighting styles using this command:pandoc --list-highlight-styles
. I did have to troubleshoot some errors, which led me to this post to solve all of my issues. Commented Oct 7 at 1:39
Try this software:
https://github.com/BlueHatbRit/mdpdf
Or explain what tools you've tried and why those are not working fine.
Also check this question on superuser:
https://superuser.com/questions/689056/how-can-i-convert-github-flavored-markdown-to-a-pdf
-
2I prefer Pandoc (because it is a Swiss knife to convert files) superuser.com/a/715340/791887 Commented Jul 2, 2019 at 10:20
-
I can't get
mdpdf
to work--not sure if it's an installation error or what.$ mdpdf README.md
-->Error: Browser is not downloaded. Run "npm install" or "yarn install" at ChromeLauncher.launch (/usr/local/lib/node_modules/mdpdf/node_modules/puppeteer/lib/Launcher.js:236:15)
. Giving up and trying one of the other options at the superuser Q&A you posted in your answer. Commented Oct 7, 2020 at 6:47 -
1
-
I found md-to-pdf very useful.
Examples:
– Convert ./file.md and save to ./file.pdf
$ md-to-pdf file.md
– Convert all markdown files in current directory
$ md-to-pdf ./*.md
– Convert all markdown files in current directory recursively
$ md-to-pdf ./**/*.md
– Convert and enable watch mode
$ md-to-pdf ./*.md -w
And many more options.