Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I export a Markdown file as a PDF using the exact same style as GitHub? [closed]

I'm preparing some .md wiki documents for the new developers entering my project and I want to export them as PDFs. They have to be PDFs, sadly it is a requirement.

My problem is that I want the documents to have the same style GitHub has, or even the one VSCode has for their markdown preview. Every tool I tried didn't use the exact same style as GitHub. They where similar, but not the same or as close enough to pass.

Here's what I tried:

  1. Using Markdown editors: Typora, Obsidian, Dillinger. None of the GitHub-named themes or presets looked acceptable.

  2. CLI tools: Didn't really tried this one. They weren't more promising than the others and required more work, and also I'm using Windows so that added an extra layer of complexity.

  3. Browser extensions: None looked acceptable.

  4. VSCode extensions: None looked acceptable.

  5. Using a custom .css file on editors and IDEs: My best shot. I tried downloading the GitHub CSS stylesheet and applying it to Typora, Obsidian, and some VSCode extensions. I also tried many other solutions that are too much to add to this post, but my closest try was to use the Markdown PDF extension for VSCode with a custom CSS file but I coudn't get the extension to make use of the stylesheet. I know it is possible and likely very simple to do it but I've never worked with CSS and styling and I am very lost.

 

Simply put, I want a way to make a PDF out of my MD files and with the same style GitHub.com uses for its README.md files. I don't want any style that looks similar to it, I want it to look exactly the same. As a second choice I can be happy with the style that VSCode uses for its MD preview tab.

If there is no way to plainly export MD->PDF I am fine with doing MD->HTML->PDF or whatever steps necessary.

like image 718
ff yeins Avatar asked Oct 29 '25 22:10

ff yeins


2 Answers

Using the Markdown Preview Enhance VSCode extension, you can export the markdown into HTML. It also gives the option to export directly into a PDF, but the style gets changed. To preserve the style, first save it as an HTML file, and then you can convert the HTML file into a pdf.

like image 68
Hemanta Adhikari Avatar answered Nov 01 '25 03:11

Hemanta Adhikari


I had faced same issue today. My approch was I export the .md file as HTML. Then I opened the HTML file in browser(firefox) from there select print option to convert it into pdf.

Point to be noted that, I have mathematical eqn. (latex), tables in my .md file, possibly due to which the online converter can't convert the HTML to PDF too accurately as the Markdown Preview Enhanced extension potraying.

like image 20
Mr. Ghosh Avatar answered Nov 01 '25 01:11

Mr. Ghosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!