Workflow: Markdown To Nice PDF

Every so often I want to make a nice PDF from some text which is currently formatted in Markdown and I often do this by sharing the text to Workflow. Unfortunately by default when you make rich text from markdown in Workflow you end up with something like this:

Yes, that’s Times New Roman. Not a font I usually use by choice. Thankfully however it’s quite simple to fix this with my Workflow. This can be accomplished in a number of ways, I convert the rich text to HTML, replace the <body> tag with one containing a HTML inline style (<body style="font-family: Arial, Helvetica, sans-serif;">), make rich text from that HTML, and then make the PDF. The body in HTML is where all of your content is, so this will then apply to all of your text. If you just wanted to change the first level of headings, you could replace the <h1> tags instead.

This is how the whole Workflow runs:

  • Make Rich Text from Markdown
  • Make HTML from Rich Text
  • Replace Text, this is where I replace the body tag.
  • Make Rich Text from HTML
  • Make PDF, make sure that include margin is enabled otherwise the PDF looks funny.

Bonus: The PDF contains the text as well, so it’s searchable and also accessible. All you need to do is to add an action at the end of the Workflow to make it do what you want with it, you could quick look it, share it, open it in another application or save it somewhere you choose!

You can get the simplest workflow here: Markdown To Nice PDF

It would also be possible to link a style sheet, such as the [Pure CSS] one, by adding the css link to the <head> tag, the caveat of this is most pre-built CSS files work best when you add classes to sections (e.g. <table> would be <table class="pure-table">), which will require many more Replace Text actions if you want to account for all the possibilities.

If you want the Pure CSS version is also available.


AIRPRESS LOADED