Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

gfm-pdf

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gfm-pdf

A CLI tool to convert Markdown files to PDF with support for math formulas, Mermaid diagrams, and syntax highlighting

latest
Source
npmnpm
Version
1.0.8
Version published
Weekly downloads
6
-60%
Maintainers
1
Weekly downloads
 
Created
Source

gfm-pdf

A command-line tool that converts Markdown files to PDF with support for math formulas, Mermaid diagrams, and syntax highlighting. Designed for creating single-page PDFs optimized for e-ink devices and technical documentation.

npm version license downloads

Features

  • 📝 GitHub Flavored Markdown support (tables, task lists, strikethrough)
  • 🧮 Mathematical formulas using KaTeX
  • 📊 Mermaid diagrams (flowcharts, sequence diagrams, git graphs, etc.)
  • 🎨 Syntax highlighting for code blocks with multiple themes
  • 📄 Single-page PDF output optimized for e-ink devices
  • 🎯 Multiple page formats (A4, A3, Letter, Legal)
  • 🎨 Custom CSS styling support
  • Fast rendering using Playwright
  • 🔧 Configurable options for all features

Installation

npm install -g gfm-pdf

Local Installation

npm install gfm-pdf

Usage

Basic Usage

gfm-pdf input.md

This will convert input.md to input.pdf in the same directory.

Specify Output File

gfm-pdf input.md -o output.pdf

Complete Example

gfm-pdf document.md \
  --output ./dist/document.pdf \
  --theme monokai \
  --format A4 \
  --margins "1in" \
  --css ./custom-styles.css \
  --verbose

Command Line Options

OptionShortDescriptionDefault
--output <path>-oOutput PDF file path{input}.pdf
--theme <theme>-tSyntax highlighting themegithub
--format <format>-fPage format (A4, A3, Letter, Legal, Singular)Singular
--margins <margins>-mPage margins in CSS format1cm
--css <path>Custom CSS file path
--no-mathDisable math formula support
--no-mermaidDisable Mermaid diagram support
--no-syntaxDisable syntax highlighting
--verbose-vEnable verbose outputfalse

Supported Features

Mathematics

Supports both inline and display math using KaTeX syntax:

Inline math: $E = mc^2$

Display math:
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$

Math in code blocks:
```math
price = \max(unitPrice, 1e18)
collateralAmount = \frac{usdAmount \times 10^{decimals}}{price}
```

Mermaid Diagrams

Supports all Mermaid diagram types:

```mermaid
flowchart TD
    A[Start] --> B{Decision}
    B -->|Yes| C[Success]
    B -->|No| D[Retry]
```

```mermaid
sequenceDiagram
    User->>API: Request
    API-->>User: Response
```

Code Syntax Highlighting

Supports 100+ programming languages:

```javascript
function hello(name) {
  console.log(`Hello, ${name}!`);
}
```

```python
def fibonacci(n):
    return n if n <= 1 else fibonacci(n-1) + fibonacci(n-2)
```

GitHub Flavored Markdown

  • ✅ Tables
  • ✅ Task lists
  • ✅ Strikethrough text
  • ✅ Blockquotes
  • ✅ Links and images
  • ✅ Nested lists

Custom Styling

You can customize the PDF appearance using a CSS file:

/* custom-styles.css */
body {
  font-family: 'Georgia', serif;
  line-height: 1.8;
  color: #2c3e50;
}

h1, h2, h3 {
  color: #34495e;
  border-bottom: 2px solid #3498db;
  padding-bottom: 0.3em;
}

pre {
  background-color: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  padding: 16px;
}

blockquote {
  border-left: 4px solid #3498db;
  margin: 0;
  padding-left: 1em;
  font-style: italic;
}

Then use it with:

gfm-pdf document.md --css custom-styles.css

E-ink Device Optimization

The tool is specifically designed for e-ink devices with these optimizations:

  • Single-page layout - No page breaks for continuous reading
  • High contrast - Black text on white background
  • Proper margins - Comfortable reading spacing
gfm-pdf document.md \
  --format A4 \
  --margins "1.5cm" \
  --theme github \
  --output document.pdf

Examples

Technical Documentation

Perfect for converting technical docs with code examples, diagrams, and formulas:

gfm-pdf api-documentation.md \
  --output ./docs/api-guide.pdf \
  --theme vs-code-dark \
  --format A4

Academic Papers

Ideal for research papers with mathematical notation:

gfm-pdf research-paper.md \
  --output paper.pdf \
  --format Letter \
  --margins "2cm" \
  --theme github

Architecture Diagrams

Great for system design documents with Mermaid diagrams:

gfm-pdf system-design.md \
  --output architecture.pdf \
  --format A3 \
  --verbose

Troubleshooting

Common Issues

"Input file does not exist"

  • Check the file path and ensure the file exists
  • Use absolute paths if relative paths don't work

"Playwright browser not found"

  • Run npx playwright install to install required browsers
  • This happens automatically during npm install

Math formulas not rendering

  • Ensure you're using proper KaTeX syntax
  • Check for unclosed math delimiters ($ or $$)

Mermaid diagrams not appearing

  • Verify your Mermaid syntax is correct
  • Test diagrams on Mermaid Live Editor

Custom CSS not applied

  • Check the CSS file path is correct
  • Ensure CSS syntax is valid

Performance Tips

  • For large documents, consider splitting into smaller files
  • Use --verbose flag to monitor conversion progress
  • Custom CSS can impact rendering speed

Development

Building from Source

git clone https://github.com/arash16/gfm-pdf
cd gfm-pdf
npm install
npm run build

Running in Development

npm run dev input.md --output output.pdf

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Support

Made with KosseKhari Methodologies ❤️ (Vibe Coding)

Keywords

markdown

FAQs

Package last updated on 25 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts