Guide
How to Trigger Markdown to PDF Conversions with Webhooks
Updated July 10, 2026
Webhooks are the primary way systems talk to each other in real-time. When a user updates a blog post in a headless CMS, makes a payment on Stripe, or pushes documentation to GitHub, a webhook fires to alert other services. If your business relies on automatically generating invoices, certificate PDFs, or offline documentation, learning how to trigger markdown to pdf webhook endpoints will streamline your entire automation pipeline.
In this guide, we will build a serverless endpoint using Node.js and Express to listen for webhooks and automatically render Markdown documents into styled PDFs.
How the Webhook Flow Works
Before diving into the code, let’s understand the flow:
- The Source Event: An external platform (like Strapi, GitHub, or Shopify) triggers an event.
- The Webhook Request: The source sends a HTTP POST request with a JSON payload containing the Markdown content or document metadata.
- The PDF Service: Our web service receives the request, processes the Markdown, applies styling, compiles the PDF, and saves it.
- The Destination: The service uploads the generated PDF to a cloud storage bucket (like AWS S3) or emails it directly.
Writing the Webhook Receiver Endpoint
Here is a clean Node.js endpoint using Express and Puppeteer to handle incoming webhook triggers:
import express from 'express';
import { marked } from 'marked';
import puppeteer from 'puppeteer';
import fs from 'fs';
const app = express();
app.use(express.json()); // Parse JSON payloads
app.post('/webhooks/generate-pdf', async (req, res) => {
const { title, content, styleUrl } = req.body;
if (!content) {
return res.status(400).json({ error: 'Markdown content is required' });
}
try {
// 1. Parse markdown content to HTML
const htmlBody = marked.parse(content);
// Wrap in standard page template
const fullHtml = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>${title || 'Generated Document'}</title>
${styleUrl ? `<link rel="stylesheet" href="${styleUrl}">` : ''}
</head>
<body>
<div class="pdf-container">
${htmlBody}
</div>
</body>
</html>
`;
// 2. Launch Puppeteer
const browser = await puppeteer.launch({ headless: 'new' });
const page = await browser.newPage();
await page.setContent(fullHtml, { waitUntil: 'networkidle0' });
// 3. Print page layout to PDF
const filename = `document-${Date.now()}.pdf`;
const outputPath = `./downloads/${filename}`;
await page.pdf({
path: outputPath,
format: 'A4',
margin: { top: '20mm', right: '20mm', bottom: '20mm', left: '20mm' },
printBackground: true
});
await browser.close();
console.log(`Successfully compiled PDF: ${outputPath}`);
// Return the download path or URL to the caller
return res.status(200).json({
success: true,
message: 'PDF generated successfully',
pdfUrl: `https://exports.yoursite.com/downloads/${filename}`
});
} catch (error) {
console.error('Error generating PDF:', error);
return res.status(500).json({ error: 'Internal server error rendering PDF' });
}
});
app.listen(3000, () => console.log('Webhook PDF processor listening on port 3000'));
Connecting Common Platforms
You can point webhook URLs from various applications to this endpoint:
GitHub Webhooks
Configure your GitHub repository settings to send a payload on Push events. Your script can then extract the modified markdown files and build a compile script.
Headless CMS (Strapi, Contentful)
Configure the CMS to hit /webhooks/generate-pdf whenever a post is published, allowing your editorial team to download a matching print-ready copy immediately.
Handling Scalability and Queueing
If your webhook endpoints experience high traffic (for example, generating thousands of invoices simultaneously), rendering them synchronously can overload your server’s memory. In a production scenario, you should decouple this using a message broker like BullMQ or RabbitMQ. The webhook receiver simply pushes a task onto the queue, and background workers process the PDFs one-by-one.
Conclusion
Using webhooks to trigger Markdown to PDF conversions allows you to connect multiple applications together into a cohesive, automated content workflow. If you want to experiment with different Markdown layouts and export files manually, remember you can always use our free online editor.
Written by Markdown to PDF Editorial Team
Our team specializes in document design, web standards, and developer utilities. This guide was researched and vetted against current browser printing standards and Paged.js specifications. Learn more on our About page.
Try it yourself — free, no signup
Convert your Markdown to a polished PDF right in your browser.
Open the editor