ThoughtsInWords

PodPDF: Free & Open Source PDF Generator

PodPDF is a lightweight, open-source utility powered by Bun to convert Markdown files into professional PDFs. Unlike paid SaaS solutions, PodPDF runs locally on your machine, ensuring zero cost, total privacy, and lightning-fast performance.

This guide provides a checklist of steps to build and use the PodPDF script locally.

🚀 Setup Checklist

Get your environment ready for PodPDF.

�️ Implementation Checklist

Create the podpdf.ts script to handle the conversion.

The Script (podpdf.ts)

import puppeteer from "puppeteer";
import MarkdownIt from "markdown-it";

const md = new MarkdownIt();
const inputFile = process.argv[2];
const outputFile = process.argv[3] || "output.pdf";

if (!inputFile) {
  console.error("Usage: bun podpdf.ts <input.md> [output.pdf]");
  process.exit(1);
}

try {
  // 1. Read Markdown
  const markdown = await Bun.file(inputFile).text();

  // 2. Convert to HTML with basic styling
  const html = `
    <!DOCTYPE html>
    <html>
      <head>
        <style>
          body { font-family: 'Helvetica', sans-serif; padding: 40px; line-height: 1.6; }
          h1 { border-bottom: 2px solid #333; padding-bottom: 10px; }
          table { width: 100%; border-collapse: collapse; margin: 20px 0; }
          th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
          th { background-color: #f4f4f4; }
          code { background: #f4f4f4; padding: 2px 5px; border-radius: 4px; }
        </style>
      </head>
      <body>
        ${md.render(markdown)}
      </body>
    </html>
  `;

  // 3. Generate PDF
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setContent(html, { waitUntil: "networkidle0" });
  await page.pdf({ path: outputFile, format: "A4", printBackground: true });

  await browser.close();
  console.log(`✅ PDF created: ${outputFile}`);

} catch (error) {
  console.error("Error generating PDF:", error);
}

� Usage Checklist

Once your script is ready, follow this flow to generate a PDF.

1. Prepare Your Content

2. Run the Converter

💡 Quick Example: Simple Invoice

Create a file named invoice.md with the following content to test your setup.

# Invoice #001

**From:** My Company Inc.
**To:** Jane Doe

| Item | Qty | Price |
| :--- | :-- | :---- |
| Consulting | 10 | $1500 |
| Setup Fee  | 1  | $200  |

**Total: $1700**

Run:

bun podpdf.ts invoice.md invoice.pdf

By following this guide, you have a completely free, open-source, and customizable PDF generator using the power of Bun.