How can I create plaintext files with Markdown syntax and convert them to PDF format?

Solution 1:

I use Marked to process text files to pdf routinely.

No matter what editor you use, Marked will open and re-save a PDF generated from the plain text input by opening and re-saving the file.

It also saves to HTML or RDF output from markdown.

In reality, any program that renders markdown could print to PDF using OS X core services (File -> Print -> PDF -> Save as PDF), but I much prefer having Marked for it's multitude of handy and flexible processing options and it's ability to live preview markdown files as I edit them in another editor:

  • Printing: TOC, suppressing link underline colors, better page breaks
  • Multiple styles of markdown rendering
  • Support for custom processors, all manner of smart (and dumb) typography
  • overall clean, fast, robust, elegant software for a very reasonable price

Solution 2:

install markdown (which is a perl script) from here: http://daringfireball.net/projects/markdown/

(Alternately you can use homebrew (Link) to install markdown, or one of the many enhanced markdown utilities)

Then once you have your markdown text file (say it's text.md) you can simply run:

$ perl *pathto*/markdown.pl text.md > text.html in the terminal

then open the resulting text.html in Safari (or any other web browser) and Print to PDF.

If you are extensively converting markdown to pdf you can simplify this by using pandoc: http://johnmacfarlane.net/pandoc/

Better yet, there are a number of text editors designed specifically for Markdown that seem to do the job for you. (Though you may want to check for pdf export... for example iA Writer only exports to RTF or HTML... the conversion of one of those to PDF is trivial, but it's an extra step).

Many general purpose text editors (TextMate, BBEdit) can be used well for Markdown. (For example in the latest TextMate 2 Beta you can select Preview from the Markdown bundle and then export the formatted document to PDF from the Print dialog.)