Blog

Markdown to PDF: Complete Guide with Examples

Converting Markdown to PDF is a common requirement for technical documentation, reports, README files, and automated document generation. Whether you're creating API documentation, generating reports from Markdown files, or building automated workflows, having a reliable Markdown to PDF converter is essential.

Markdown's simplicity makes it the preferred format for developers and technical writers. According to Stack Overflow's 2023 Developer Survey, over 80% of developers use Markdown regularly for documentation. However, when it comes to sharing or archiving these documents, PDF remains the universal standard.

This comprehensive guide covers everything you need to know about Markdown to PDF conversion, including handling complex tables, page breaks, code blocks, and styling. We'll explore practical examples using CustomJS's Markdown to PDF API, which offers 600 free conversions per month and seamless integration with Make.com and n8n.

TL;DR

  • CustomJS Markdown to PDF API converts Markdown files to professional PDFs with full support for tables, code blocks, and custom styling.
  • Free tier includes 600 PDF conversions per month, making it cost-effective for most projects.
  • Supports advanced features like page breaks, long table handling, and responsive layouts.
  • Direct integration with Make.com and n8n for automated document generation workflows.
  • Simple REST API that works with any programming language (Python, JavaScript, PHP, etc.).

What is Markdown to PDF Conversion?

Markdown to PDF conversion transforms lightweight Markdown syntax into professionally formatted PDF documents. Unlike basic HTML to PDF conversion, Markdown to PDF specifically handles Markdown's unique syntax including headers, lists, code blocks, tables, and inline formatting.

The conversion process typically involves parsing Markdown syntax, converting it to HTML, applying CSS styling, and rendering the final PDF. A good Markdown PDF generator preserves formatting, handles page breaks intelligently, and maintains code block readability.

Common use cases include generating technical documentation, creating reports from Markdown files, automating README to PDF conversion, and building documentation pipelines in CI/CD workflows.

How CustomJS Converts Markdown to PDF

CustomJS provides a straightforward Markdown to PDF API that handles the entire conversion process. Simply send your Markdown content via a POST request, and receive a professionally formatted PDF in response.

The API supports standard Markdown syntax including headers, bold/italic text, lists, links, images, tables, and code blocks. It automatically applies sensible defaults for styling while allowing customization through CSS.

The interactive widget above demonstrates real-time Markdown to PDF conversion. Try modifying the Markdown content to see how different elements render in the PDF output.

Basic Markdown to PDF Example

Here's a simple example using the CustomJS API to convert Markdown to PDF. This works with any HTTP client in any programming language.

cURL Example

curl -X POST 'https://e.customjs.io/markdown2pdf' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "input": {
      "markdown": "# Hello World\n\nThis is **bold** text."
    }
  }' \
  > output.pdf

JavaScript/Node.js Example

const axios = require('axios');
const fs = require('fs');

async function convertMarkdownToPdf(markdown) {
  const response = await axios.post(
    'https://e.customjs.io/markdown2pdf',
    {
      input: { markdown }
    },
    {
      headers: {
        'x-api-key': 'YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    }
  );
  
  fs.writeFileSync('output.pdf', response.data);
  console.log('PDF generated successfully!');
}

const markdown = `
# Technical Documentation

## Features
- Easy to use
- Fast conversion
- Professional output

\`\`\`javascript
console.log('Hello World');
\`\`\`
`;

convertMarkdownToPdf(markdown);

Python Example

import requests

def convert_markdown_to_pdf(markdown_content):
    url = 'https://e.customjs.io/markdown2pdf'
    headers = {
        'x-api-key': 'YOUR_API_KEY',
        'Content-Type': 'application/json'
    }
    payload = {
        'input': {
            'markdown': markdown_content
        }
    }
    
    response = requests.post(url, json=payload, headers=headers)
    
    with open('output.pdf', 'wb') as f:
        f.write(response.content)
    
    print('PDF generated successfully!')

markdown = """
# Project Report

## Summary
This report contains important findings.

| Metric | Value |
|--------|-------|
| Users  | 1,000 |
| Revenue| $50K  |
"""

convert_markdown_to_pdf(markdown)

Handling Tables in Markdown PDF

Tables are one of the most challenging aspects of Markdown to PDF conversion. Long tables can break across pages awkwardly, and wide tables may overflow page margins.

Basic Table Example

Standard Markdown tables work seamlessly with the CustomJS API:

| Feature | CustomJS | Alternative A | Alternative B |
|---------|----------|---------------|---------------|
| Free Tier | 600/month | 100/month | None |
| Price | $9/mo | $29/mo | $49/mo |
| Integration | Make, n8n | API only | API only |
| Support | Email, Docs | Email | Enterprise only |

Page Break Strategies for Long Tables

For tables that span multiple pages, you have several options:

  • Split tables manually: Break large tables into smaller sections with descriptive headers.
  • Use landscape orientation: For wide tables, consider rotating the page (requires custom CSS).
  • Responsive table patterns: Use CSS to make tables scroll horizontally or wrap content.
  • Summary tables: Create condensed versions for PDF while linking to full data.

Styling Tables with CSS

While the Markdown to PDF API applies default styling, you can enhance tables by converting to HTML first and using the HTML to PDF API with custom CSS:

<style>
table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
}

th {
  background-color: #4f46e5;
  color: white;
  padding: 12px;
  text-align: left;
  font-weight: 600;
}

td {
  padding: 10px;
  border-bottom: 1px solid #e5e7eb;
}

tr:nth-child(even) {
  background-color: #f9fafb;
}

tr:hover {
  background-color: #f3f4f6;
}
</style>

Code Blocks in Markdown PDF

Code blocks are essential for technical documentation. The CustomJS Markdown to PDF API preserves code formatting and applies syntax-friendly styling.

Inline Code

Use single backticks for inline code: const result = data.map()

Multi-line Code Blocks

Use triple backticks with optional language specification:

```javascript
async function fetchData() {
  const response = await fetch('/api/data');
  const data = await response.json();
  return data;
}
```

Preventing Code Block Page Breaks

To keep code blocks together on one page, you can use the HTML to PDF API with custom CSS:

pre {
  page-break-inside: avoid;
  background-color: #1f2937;
  color: #e5e7eb;
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.5;
}

Advanced Markdown to PDF Features

Page Breaks

Control where pages break by using HTML comments or converting to HTML first:

# Section 1

Content for section 1...

<div style="page-break-after: always;"></div>

# Section 2

Content for section 2...

Headers and Footers

For documents requiring headers and footers with page numbers, use the HTML to PDF API which offers more control:

@page {
  margin-top: 2cm;
  margin-bottom: 2cm;
  
  @top-center {
    content: "Company Documentation";
    font-size: 10pt;
    color: #6b7280;
  }
  
  @bottom-right {
    content: "Page " counter(page) " of " counter(pages);
    font-size: 10pt;
    color: #6b7280;
  }
}

Custom Styling

Apply custom fonts, colors, and spacing by first converting Markdown to HTML, then using the HTML to PDF API:

body {
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.6;
  color: #1f2937;
  max-width: 800px;
  margin: 0 auto;
  padding: 40px;
}

h1 {
  color: #4f46e5;
  font-size: 28pt;
  margin-top: 0;
  margin-bottom: 20px;
  border-bottom: 3px solid #4f46e5;
  padding-bottom: 10px;
}

h2 {
  color: #6366f1;
  font-size: 20pt;
  margin-top: 30px;
  margin-bottom: 15px;
}

Real-World Use Cases

1. API Documentation Generation

Automatically convert API documentation written in Markdown to PDF for distribution:

const fs = require('fs');
const axios = require('axios');

async function generateAPIDocs() {
  const markdown = fs.readFileSync('API_DOCS.md', 'utf8');
  
  const response = await axios.post(
    'https://e.customjs.io/markdown2pdf',
    { input: { markdown } },
    {
      headers: {
        'x-api-key': 'YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    }
  );
  
  fs.writeFileSync('API_Documentation.pdf', response.data);
  console.log('API documentation PDF generated!');
}

generateAPIDocs();

2. README to PDF Conversion

Convert GitHub README files to PDF for offline documentation or archival:

import requests

def readme_to_pdf(github_url):
    # Fetch README from GitHub
    readme_response = requests.get(github_url)
    markdown_content = readme_response.text
    
    # Convert to PDF
    pdf_response = requests.post(
        'https://e.customjs.io/markdown2pdf',
        json={'input': {'markdown': markdown_content}},
        headers={
            'x-api-key': 'YOUR_API_KEY',
            'Content-Type': 'application/json'
        }
    )
    
    with open('README.pdf', 'wb') as f:
        f.write(pdf_response.content)

readme_to_pdf('https://raw.githubusercontent.com/user/repo/main/README.md')

3. Automated Report Generation

Generate weekly reports from Markdown templates with dynamic data:

async function generateWeeklyReport(data) {
  const markdown = `
# Weekly Report - Week ${data.weekNumber}

## Summary
Total users: ${data.totalUsers}
New signups: ${data.newSignups}
Revenue: $${data.revenue}

## Top Features Used
${data.topFeatures.map((f, i) => `${i + 1}. ${f.name} (${f.usage} uses)`).join('\n')}

## Issues Resolved
${data.issues.map(i => `- ${i.title} (#${i.number})`).join('\n')}
`;

  const response = await axios.post(
    'https://e.customjs.io/markdown2pdf',
    { input: { markdown } },
    {
      headers: {
        'x-api-key': 'YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    }
  );
  
  return response.data;
}

4. Documentation Pipeline in CI/CD

Integrate Markdown to PDF conversion in your CI/CD pipeline:

# .github/workflows/docs.yml
name: Generate Documentation PDF

on:
  push:
    branches: [main]
    paths:
      - 'docs/**/*.md'

jobs:
  generate-pdf:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      
      - name: Combine Markdown files
        run: cat docs/*.md > combined.md
      
      - name: Convert to PDF
        run: |
          curl -X POST 'https://e.customjs.io/markdown2pdf' \
            -H "x-api-key: ${{ secrets.CUSTOMJS_API_KEY }}" \
            -H 'Content-Type: application/json' \
            -d @- > documentation.pdf << EOF
          {
            "input": {
              "markdown": $(cat combined.md | jq -Rs .)
            }
          }
          EOF
      
      - name: Upload PDF artifact
        uses: actions/upload-artifact@v2
        with:
          name: documentation
          path: documentation.pdf

Integration with Make.com and n8n

CustomJS offers native modules for Make.com and n8n, making it easy to integrate Markdown to PDF conversion into no-code workflows.

Make.com Integration

Use the CustomJS module in Make.com to convert Markdown to PDF without writing code:

  1. Add the CustomJS module to your scenario
  2. Select "Execute JavaScript" or use the native API endpoint
  3. Pass your Markdown content as input
  4. Receive the PDF as base64 or URL
  5. Send to email, Google Drive, Dropbox, etc.

Learn more in our Make.com integration guide.

n8n Integration

Similarly, n8n users can leverage CustomJS nodes for Markdown to PDF conversion:

  1. Install the CustomJS n8n node
  2. Configure your API key
  3. Use the Markdown to PDF function
  4. Connect to other nodes for complete automation

Check out our n8n integration documentation.

Markdown to PDF vs HTML to PDF

While both approaches convert content to PDF, they serve different purposes:

FeatureMarkdown to PDFHTML to PDF
Best ForDocumentation, README files, simple reportsInvoices, complex layouts, custom designs
Styling ControlLimited (default styles)Full control with CSS
Ease of UseVery easy (Markdown syntax)Moderate (HTML/CSS knowledge)
TemplatesNot supportedNunjucks templating available
Use CaseTechnical docs, reportsBusiness docs, invoices, certificates

For maximum flexibility, you can convert Markdown to HTML first, apply custom styling, then use the HTML to PDF API for the final conversion.

Best Practices for Markdown to PDF

1. Keep Tables Concise

Limit table columns to 4-5 for optimal PDF rendering. For wider tables, consider splitting into multiple tables or using landscape orientation.

2. Use Descriptive Headers

Clear heading hierarchy (H1, H2, H3) improves PDF navigation and readability. This also helps with automatic table of contents generation.

3. Test Code Block Lengths

Very long code blocks may break awkwardly across pages. Consider splitting long code examples or using the HTML to PDF API with page-break-inside: avoid.

4. Optimize Images

Use appropriately sized images (max 800px width) to prevent overflow. Consider using relative URLs or base64-encoded images for portability.

5. Add Metadata

When using the HTML to PDF API, include document metadata for better organization:

<meta name="author" content="Your Name">
<meta name="subject" content="Technical Documentation">
<meta name="keywords" content="API, Documentation, Guide">

Pricing and Limits

CustomJS offers transparent, developer-friendly pricing for Markdown to PDF conversion:

  • Free Tier: 600 PDF conversions per month (no credit card required)
  • Starter Plan: $9/month for 3,000 conversions
  • Growth Plan: $29/month for 15,000 conversions
  • Enterprise: Custom pricing for high-volume needs

Each Markdown to PDF conversion counts as one API call. There are no hidden fees or per-page charges. Compare this to alternatives like DocRaptor ($15/1,000 PDFs) or PDF.co ($24.99/month for limited conversions).

Start free with 600 PDFs per month

Frequently Asked Questions

1. What Markdown syntax is supported?

CustomJS supports standard Markdown syntax including headers, bold/italic, lists, links, images, tables, code blocks, and blockquotes. Extended Markdown features like footnotes and task lists are also supported.

2. Can I customize the PDF styling?

The Markdown to PDF API applies sensible default styles. For custom styling, convert your Markdown to HTML first, then use the HTML to PDF API with custom CSS for full control over fonts, colors, spacing, and layout.

3. How do I handle page breaks in long documents?

Use HTML div elements with page-break-after: always style, or convert to HTML first for more granular control over page breaks using CSS @page rules.

4. Can I add headers and footers to the PDF?

Headers and footers with page numbers require using the HTML to PDF API with CSS @page rules. The Markdown to PDF API focuses on content conversion with default margins.

5. What's the maximum file size for Markdown input?

The API accepts Markdown content up to 10MB. For larger documents, consider splitting into multiple files or using pagination strategies.

6. How fast is the conversion?

Most Markdown to PDF conversions complete in under 2 seconds. Complex documents with many images or tables may take slightly longer (3-5 seconds).

7. Can I use this in Make.com or n8n?

Yes! CustomJS offers native modules for both Make.com and n8n, making it easy to integrate Markdown to PDF conversion into no-code workflows.

8. Is there a difference between Markdown to PDF and HTML to PDF?

Yes. Markdown to PDF is optimized for simple documentation with default styling. HTML to PDF offers full control with custom CSS, templates, and advanced features. See the comparison table above for details.

Conclusion

Converting Markdown to PDF doesn't have to be complicated or expensive. CustomJS provides a straightforward API that handles the entire conversion process, from parsing Markdown syntax to generating professional PDFs.

With 600 free conversions per month, native Make.com and n8n integration, and support for tables, code blocks, and custom styling, CustomJS is the ideal solution for developers and businesses automating document generation.

Whether you're generating API documentation, converting README files, or building automated report pipelines, the Markdown to PDF API offers the flexibility and reliability you need.

Get started free today

Related Articles

Continue reading on similar topics

PDF Generation in Power Automate: Complete Guide 2025
·Guide

PDF Generation in Power Automate: Complete Guide 2025

Generate professional PDFs in Power Automate with CustomJS. Create invoices, receipts, reports, and certificates with custom HTML templates, QR codes, and advanced formatting. No Azure Functions required.

power-automatepdfhtml-to-pdf
Make.com PDF Generation: Complete Guide 2025
·Guide

Make.com PDF Generation: Complete Guide 2025

Learn how to automate PDF generation in Make.com with CustomJS. Step-by-step guide with templates for invoices, HTML to PDF, and page extraction. 600 free PDFs/month.

makepdfautomation