kdp-book-generator
v1.0.4
Published
Generate KDP-compliant PDFs and EPUBs from Markdown for Amazon book publishing
Downloads
19
Maintainers
Readme
KDP Book Generator
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-generatorOr use directly with npx:
npx kdp-book-generator generate my-book.mdQuick Start
- 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...- Generate your PDF:
kdp-generator generate my-book.md --output my-book.pdf --format 6x9CLI Usage
Generate PDF
kdp-generator generate <input.md> [options]Generate EPUB (for Kindle)
kdp-generator generate <input.md> --output book.epub --format kindleOptions:
-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 formatsGenerate Configuration File
kdp-generator config --output book-config.jsonValidate Configuration
kdp-generator validate book-config.jsonAssemble 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 kindleConfiguration
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 exampleassembly-config.yaml- Multi-file book assemblysimple-config.json- Basic configuration
See the templates/ directory for:
book-assembly-template.yaml- Comprehensive assembly templatesimple-book-assembly.yaml- Minimal assembly exampletextbook-assembly.yaml- Academic book structurenovel-assembly.yaml- Fiction book structure
Documentation
- Multi-File Assembly Guide - Combine multiple files into books
- EPUB/Kindle Guide - Generate e-books for Amazon KDP
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 testLicense
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
