npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kdp-book-generator

v1.0.4

Published

Generate KDP-compliant PDFs and EPUBs from Markdown for Amazon book publishing

Downloads

19

Readme

KDP Book Generator

CI npm version License: MIT Node.js Version

A powerful tool to generate KDP-compliant PDFs from Markdown files for Amazon book publishing.

Features

  • KDP Compliance: Automatic margin calculation, font embedding, and format validation
  • 📐 Multiple Formats: Support for all standard KDP book sizes (6"x9", 5.5"x8.5", etc.)
  • 🎨 Precise Typography: Full control over fonts, spacing, and layout
  • 📄 Professional Layout: Page numbers, table of contents, chapter breaks
  • 🖨️ Print Ready: 300 DPI support with optional bleed
  • Fast Generation: Playwright-based PDF generation for consistent results
  • 📱 EPUB/Kindle Support: Generate e-books for Kindle Direct Publishing
  • 📚 Multi-file Assembly: Combine multiple Markdown files into complete books

Installation

npm install -g kdp-book-generator

Or use directly with npx:

npx kdp-book-generator generate my-book.md

Quick Start

  1. Create a markdown file with your book content:
---
title: "My Amazing Book"
author: "Your Name"
---

# Chapter 1: Introduction

Welcome to my book! This is the first chapter...

---

# Chapter 2: Getting Started

Here's how to get started...
  1. Generate your PDF:
kdp-generator generate my-book.md --output my-book.pdf --format 6x9

CLI Usage

Generate PDF

kdp-generator generate <input.md> [options]

Generate EPUB (for Kindle)

kdp-generator generate <input.md> --output book.epub --format kindle

Options:

  • -o, --output <output> - Output PDF file (default: book.pdf)
  • -f, --format <format> - Book format: 6x9, 5.5x8.5, 5x8, 8.5x11, 7x10, 7.5x9.25 (default: 6x9)
  • -c, --config <config> - Configuration file (JSON)
  • -t, --title <title> - Book title
  • -a, --author <author> - Book author
  • --no-toc - Disable table of contents
  • --bleed - Enable bleed (0.125" on all sides)
  • --pages <pages> - Estimated page count for margin calculation (default: 200)
  • --debug - Enable debug output

List Available Formats

kdp-generator formats

Generate Configuration File

kdp-generator config --output book-config.json

Validate Configuration

kdp-generator validate book-config.json

Assemble Multiple Files

kdp-generator assemble assembly-config.yaml --output complete-book.pdf

# For EPUB/Kindle
kdp-generator assemble assembly-config.yaml --output book.epub --format kindle

Configuration

Create a book-config.json file to customize your book:

{
  "title": "My Book",
  "author": "Author Name",
  "format": {
    "name": "6\" x 9\"",
    "width": 6,
    "height": 9,
    "unit": "in"
  },
  "margins": {
    "top": 0.25,
    "bottom": 0.25,
    "inside": 0.5,
    "outside": 0.25,
    "unit": "in"
  },
  "typography": {
    "body": {
      "family": "Times New Roman",
      "size": 11,
      "lineHeight": 1.4,
      "weight": "normal",
      "style": "normal",
      "color": "#000000",
      "marginTop": 0,
      "marginBottom": 12
    },
    "heading1": {
      "family": "Times New Roman",
      "size": 18,
      "lineHeight": 1.4,
      "weight": "bold",
      "style": "normal",
      "color": "#000000",
      "marginTop": 24,
      "marginBottom": 18
    }
  },
  "pageNumbers": {
    "enabled": true,
    "startPage": 1,
    "format": "decimal",
    "position": "footer",
    "alignment": "center"
  },
  "tableOfContents": true,
  "bleed": false
}

Markdown Features

Front Matter

Use YAML front matter to specify book metadata:

---
title: "Book Title"
author: "Author Name"
description: "Book description"
keywords: ["keyword1", "keyword2"]
language: "en"
---

Page Breaks

Use horizontal rules to force page breaks:

# Chapter 1

Content here...

---

# Chapter 2

New chapter on new page...

Table of Contents

Automatically generated from headings. Use --no-toc to disable.

Supported Elements

  • Headings: H1-H6 with automatic styling
  • Paragraphs: Justified text with proper spacing
  • Lists: Ordered and unordered lists
  • Blockquotes: Styled quote blocks
  • Code: Inline code and code blocks
  • Tables: Formatted tables with borders
  • Images: Embedded images (300 DPI recommended)
  • Links: Clickable links in PDF

Amazon KDP Compliance

Automatic Margin Calculation

Margins are automatically calculated based on your page count:

  • 24 pages or less: 0.375" inside, 0.25" outside
  • 25-150 pages: 0.5" inside, 0.25" outside
  • 151-300 pages: 0.625" inside, 0.25" outside
  • 301-500 pages: 0.75" inside, 0.25" outside
  • 501+ pages: 0.875" inside, 0.25" outside

Font Embedding

All fonts are automatically embedded in the PDF to ensure compatibility.

Quality Requirements

  • Resolution: 300 DPI for all images
  • File size: Optimized to stay under 650MB limit
  • Color mode: Proper color handling for print
  • Format compliance: Meets all KDP technical requirements

Programmatic Usage

import { generatePDF } from 'kdp-book-generator';

await generatePDF({
  input: 'my-book.md',
  output: 'my-book.pdf',
  config: {
    title: 'My Book',
    author: 'Author Name',
    format: { name: '6" x 9"', width: 6, height: 9, unit: 'in' },
    // ... other config options
  },
  debug: true
});

Examples

See the examples/ directory for:

  • sample-book.md - Complete book example
  • assembly-config.yaml - Multi-file book assembly
  • simple-config.json - Basic configuration

See the templates/ directory for:

  • book-assembly-template.yaml - Comprehensive assembly template
  • simple-book-assembly.yaml - Minimal assembly example
  • textbook-assembly.yaml - Academic book structure
  • novel-assembly.yaml - Fiction book structure

Documentation

Requirements

  • Node.js 18 or higher
  • Chromium (automatically installed with Playwright)

Development

# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode
npm run dev

# Run tests
npm test

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

For issues and questions:

  • Create an issue on GitHub
  • Check the documentation
  • Review the examples

Changelog

1.0.0

  • Initial release
  • KDP compliance features
  • Multiple format support
  • CLI interface
  • Configuration system