Last updated: September 18, 2024

<span aria-hidden="true" id="convert-markdown-files-to-html-or-pdf-in-seconds"></span>

# Convert Markdown files to HTML or PDF in seconds

![Charlie Macnamara](/assets/images/teammates/charlie.jpg?dpl=dpl_5eQDcFwLGbzg3PfkSEW2a2j2x5pY)

**Charlie Macnamara**

Technical Writer & Support Engineer · Scotland · Show bio

Markdown helps web content creators, like myself, to easily write text that is suitable for the web. It allows just enough formatting so that humans can still make sense of it, while computers are able to render it with style, using HTML and CSS. Markdown is platform-agnostic, and its syntax can be learned in as little as [five minutes⁠](https://www.markdowntutorial.com/). While some argue there are superior formats available, it stands without question that Markdown has become the lingua franca among developers who write blog posts and documentation. It's even used in many day-to-day web applications like Reddit, Gmail, and GitHub. If Markdown hasn't yet become second nature to you, there are many resources available online, such as this[cheat sheet⁠](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) that I kept on hand when I took my first steps.

![/document/convert Robot](/_next/static/immutable/media/opengraph-image.2kd_0of-zi-er.png)

The [last time we covered](/blog/2019/11/document-convert.md) our[/document/convert](/docs/robots/document-convert.md) Robot back in late 2019, theRobot was still in its infancy and could only convert between the SRT and VTT formats. Since then, the Robot has been upgraded with many additional formats.

Today, I'm happy to share that we have expanded our[/document/convert](/docs/robots/document-convert.md) Robot's file support to include Markdown! You can now automatically turn Markdown files into web pages or even PDFs. Quickly generate invoices, contracts, or sales order forms as Markdown, pass them to our[/document/convert](/docs/robots/document-convert.md) Robot, and have them rendered as PDFs to be saved in your S3 bucket. Or maybe you are selling to enterprises that require documentation to be provided as PDFs? Plug Transloadit into your CI and continue writing Markdown 😄

<span aria-hidden="true" id="how-to-convert-from-markdown-to-htmlpdf"></span>

## How to convert from Markdown to html/pdf

One new parameter for the [/document/convert](/docs/robots/document-convert.md) Robotis `markdown_format`. This parameter is necessary as Markdown has several[variants⁠](https://www.iana.org/assignments/markdown-variants/markdown-variants.xhtml) that each come with their own subtle differences. Transloadit currently supports `"commonmark"` and`"gfm"`(Github Flavoured Markdown) as values.

As we mentioned above, input files in Markdown can be converted into either `"html"` or `"pdf"` by combing this new parameter with our previously existing `format` parameter.

To guide you through the process of using this new feature, we have created the script below:

```javascript
// yarn add transloadit@3
const Transloadit = require('transloadit')

;(async () => {
  const transloadit = new Transloadit({
    authKey: process.env.TRANSLOADIT_AUTH_KEY,
    authSecret: process.env.TRANSLOADIT_AUTH_SECRET,
  })

  const assemblyStatus = await transloadit.createAssembly({
    waitForCompletion: true,
    params: {
      steps: {
        imported: {
          robot: '/http/import',
          url: 'https://raw.githubusercontent.com/transloadit/uppy/master/README.md',
        },
        converted: {
          use: 'imported',
          robot: '/document/convert',
          format: 'pdf',
          markdown_format: 'gfm',
        },
        thumbed: {
          use: 'converted',
          robot: '/document/thumbs',
          density: '300',
          trim_whitespace: false,
        },
        exported: {
          use: ['converted', 'thumbed'],
          robot: '/s3/store',
          credentials: 'demo_s3_credentials',
          url_prefix: 'https://demos.transloadit.com/',
        },
      },
    },
  })

  const pdf = assemblyStatus.results.converted[0]
  const thumb = assemblyStatus.results.thumbed[0]

  console.log(`Your PDF (${pdf.meta.page_count} pages) is ready at: ${pdf.ssl_url}`)
  console.log(`Here's a thumbnail of the first page: ${thumb.ssl_url}`)
})().catch((err) => {
  console.log(err)
  process.exit(1)
})

```

This is a Node.js script, but the workflow can now integrated into your web/mobile app, back-end service, or command-line utility via [20 convenient SDKs](/docs/sdks.md) like[Uppy⁠](https://uppy.io) or the [Go SDK](/docs/sdks/go-sdk.md), as well as directly via our[JSON REST API](/docs/api.md).

Our script is comprised of a few Steps:

* Importing a Markdown file using our [/http/import](/docs/robots/http-import.md) Robot
* Converting this Markdown to PDF
* Creating preview thumbnails of each of the PDF's pages using the[/document/thumbs](/docs/robots/document-thumbs.md) Robot
* Saving the resulting files to S3

To run the script, we used the following commands:

```bash
# I got these credentials from: https://transloadit.com/c/my-app/template-credentials
export TRANSLOADIT_AUTH_KEY=****
export TRANSLOADIT_AUTH_SECRET=********
node md-to-pdf.js

```

Then, after a few seconds, it outputs:

```plaintext
Your PDF (17 pages) is ready at: https://demos.transloadit.com/db/a36056c5f54dac975647f5a1d2cbba/README.pdf
Here's a thumbnail of the first page: ../../../../../../_assets/images/blog/2021-04-19-md-to-pdf-1.png

```

I open the thumbnail URL, and sure enough:

![Document thumbnail](/_next/static/immutable/media/2020-04-20-page_001.42uv71illxiaa.png)

You'll see that our PDF was rendered using the GitHub Markdown style. This is because, similar to the variety in formats, Markdown also supports numerous[themes⁠](https://rpubs.com/ranydc/rmarkdown%5Fthemes). To control said themes, use the`markdown_theme` parameter. Two values are currently supported: `"github"` (default) and `"bare"`.

<span aria-hidden="true" id="closing-up"></span>

## Closing up

That's all! We hope to see you include our improved[/document/convert](/docs/robots/document-convert.md) Robot in your Transloadit workflow. And as usual, please reach out on [Twitter⁠](https://twitter.com/transloadit) if you have any feedback. Know that Transloadit offers a handsome 5GB/mo of traffic with our free Community Plan. So any developer can use this without swiping their credit card. 5GB amounts to a lot of PDFs so consider [signing up](/c/signup/) 😄

[#document-convert-robot](/blog/tags/document-convert-robot.md)[#document-processing-service](/blog/tags/document-processing-service.md)[#document-thumbs-robot](/blog/tags/document-thumbs-robot.md)[#http-import-robot](/blog/tags/http-import-robot.md)[#integrations](/blog/tags/integrations.md)[#node-sdk](/blog/tags/node-sdk.md)

### 👩‍💻 Join 20k+ developers

Sign up for our [monthly newsletter](/newsletters.md) to receive direct links to 3 exclusive tech — and 2 product updates. No less, no more.

Your email:

Get access

## File uploading and encoding. Made simple.

Transloadit streamlines file handling for developers, trusted by brands like Coursera and The New York Times. We’re known for a reliable API, top-notch support, and a strong commitment to open source, with projects like [Uppy⁠](https://uppy.io) and [Tus⁠](https://tus.io) setting standards in file processing.

[Sign up](/c/)[Book a Demo](https://survey.typeform.com/to/kRg47Xi5)

No credit card needed

Cancel anytime
