How To Convert Markdown Into Pdf File In Linux OS

How to created a process for converting Markdown to PDF using Pandoc. Well, the plot is thickening… What was really good if you read this post was how quickly we can convert now. There were some things that we were ready to put up with in exchange for such a quick (several seconds) lead time.

But there were problems. As I said in another post, I was not happy with the headlines. There was a lot of empty space between things (vertically), such as code blocks and headers. And in terms of headers, LaTeX doesn’t even have the same ones as HTML. There are some “varieties” of equivalents. Instead of

they are a section and a subsection (and so on with different names at the end), and in fact, they only reach

On top of that, I tried to create a tutorial for the Elle Krout puppet certification class, and in one of the command line windows, there was a symbol (I think a checkmark) that just did not display properly. It was during this fever that I started looking for other ways to convert Markdown to PDF.

How To Convert Markdown Into Pdf File In Linux OS
How To Convert Markdown Into Pdf File In Linux OS

The Best Way To Convert

What I discovered was a similar process, but I was more familiar with it. I realized that we can use a combination of CSS / HTML to go from Markdown to PDF, still using Pandoc. I went and the results are excellent. We have a script that does this now (which we will constantly improve), and essentially it runs the pandoc command to create the HTML file from Markdown.

Then there is the WeasyPrint program that will help us with this. It creates HTML-based PDFs and stylesheets (CSS file). This is right in my alley. I’m creating sites since I still used tables for the layout (back in the 90s). The trick with this just figured out how to style things. And we did now. This means that your students receive pretty attractive study guides to help with your certificates. So how do we convert Markdown to PDF? Well, this is a fairly simple process.

We create a Markdown file, then run a script that executes a couple of commands, after asking for some input. Here is the scenario of how it sits: The comments in this Bash script explain how this works. He puts the list of markdown files in the directory where we are, offers you to copy and paste one, asks for the layout type, then creates the corresponding HTML (with Pandoc) and PDF (using WeasyPrint).

The second part (waypoint command) of this is simple. But the first (pandoc command) includes a bit more features. It looks through a custom HTML template, creates a table of contents (based on the headers in the Markdown file – H2 and H3 are what is displayed). Then he spits out the HTML document. The WeasyPrint team simply looks at the finished HTML file and CSS, creates a PDF file and removes the microphone. Instead of posting all the CSS here, I just highlight some things that make life easier for anyone who tries to do this. There is also a README.pdf file that will also explain this with illustrative examples.

Fonts Of PDF

Right at the top of the page, we are declaring fonts. We use Noto Sans and Source Code Pro at Linux Academy, but feel free to add any fonts you need there. Take the regular, bold and italic version of each. Just put them in the same directory in which we placed our catalog, and treat them like we do.

Pages

Below you will see the @ page: first. This is the cover. We announced a background image, and in the PDF example, this Pinhead is stuffy in the center of the Kankamag Highway in New Hampshire. Pay attention to the size of the image, 450 × 300. If you want an image of a different size, you will have to leave the fields. Play with him until he is where you want, then you should probably stick to images of the same size as you move forward. If you do not, you will dabble with the fields every time you do a PDF.

Leave a Reply

Your email address will not be published. Required fields are marked *