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 πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

makebook

v1.0.6

Published

πŸ“– MakeBook - Convert Markdown into beautifully formatted PDFs.

Downloads

31

Readme

πŸ“– MakeBook

MakeBook is a Node.js class that allows you to generate PDF documents from Markdown content effortlessly. It leverages the power of the makepdf library to convert Markdown into beautifully formatted PDFs. ✨

πŸš€ Features

  • Simple Configuration: Easily customize your PDF output with straightforward configuration options.
  • Markdown Support: Write your content in Markdown, and MakeBook handles the conversion.
  • Styling Options: Customize fonts, styles, and layouts to match your desired aesthetic.
  • Automatic Numbering and TOC: Automatically generate numbered headings and a table of contents.
  • Inline Formatting: Use Markdown and extended syntax for bold, italics, code, and more.
  • Block Elements: Support for paragraphs, headings, lists, code blocks, and quotes.
  • Tables and Columns: Create complex tables and column layouts with ease.
  • Transclusion: Include content from other files or images seamlessly.

πŸ› οΈ Installation

First, make sure you have Node.js and NPM installed.

npm install makebook

πŸ“š Usage

Example: Creating a Book with Minimal Configuration

Here's how you can create a PDF book by specifying only the input.baseDir in the configuration:

const fs = require('fs');
const MakeBook = require('makebook');

const config = {
    input: {
        baseDir: "my-book", // Directory containing your Markdown files
    },
    output: {
        info: {
            author: "Your Name",
            title: "My Awesome Book",
            subject: "Markdown to PDF Conversion"
        }
    }
};

const book = new MakeBook(config);

book.save('my-awesome-book.pdf')
    .then(() => {
        console.log('πŸ“„ PDF saved successfully!');
    })
    .catch(err => {
        console.error('❌ Error saving PDF:', err);
    });

βš™οΈ Configuration Options

  • input: Input options.
    • baseDir: Base directory for input files.
    • entry: Entry Markdown file (defaults to index.md if not specified).
  • output: Output options.
    • info: PDF document information (author, title, subject, etc.).
    • file: Output PDF file name.
  • fonts: Font configurations.
  • styles: Styles for different document elements.
  • define: Additional definitions for dynamic content insertion.

πŸ“ Example 1: Creating a Simple PDF from directory

const config = {
    input: {
        baseDir: "my-book",
    },
    output: {
        info: {
            author: "Your Name",
            title: "Styled Book",
            subject: "Advanced Styling"
        }
    },
    fonts: {
        Roboto: {
            normal: '**/Roboto-Regular.ttf',
            bold: '**/Roboto-Bold.ttf',
            italics: '**/Roboto-Italic.ttf',
        }
    },
    styles: {
        default: {
            fontSize: 12,
            font: 'Roboto',
        },
        h1: {
            fontSize: 24,
            bold: true,
            color: "#333333"
        },
        code: {
            font: "Roboto",
            fontSize: 10,
            color: "#FF5722"
        }
    }
};

🎨 Example 2: Using Custom Fonts and Styles

const MakeBook = require('makebook');

const config = {
    output: {
        info: {
            author: "Jane Smith",
            title: "Custom Example",
            subject: "Some countries"
        }
    },
    styles: {
        default: {
            fontSize: 10,
            lineHeight: 1.5
        },
        h1: {
            fontSize: 22,
            bold: true,
            color: "#4CAF50"
        }
    }
};

const book = new MakeBook(config);

book.content(`
# πŸ–ŒοΈ Custom Example

## Here's a list of some countries from around the world:

- πŸ‡¦πŸ‡· Argentina
- πŸ‡―πŸ‡΅ Japan
- πŸ‡§πŸ‡· Brazil
- πŸ‡¦πŸ‡Ί Australia
- πŸ‡©πŸ‡ͺ Germany
`);

const fontInconsolata = {
    normal: '**/Inconsolata-Regular.ttf',
    bold: '**/Inconsolata-Bold.ttf',
    italics: '**/Inconsolata-Italic.ttf'
};

book.font(fontInconsolata)
    .save('custom-styles.pdf')
    .then(() => {
        console.log('πŸ“„ PDF saved successfully!');
    })
    .catch(err => {
        console.error('❌ Error saving PDF:', err);
    });

πŸ§ͺ Check Examples

For more you can refer to the /demo directory in the project repository. These demonstrations provide structured illustrations of various features and configurations:

  1. Manual:

    • File: /demo/demo_manual.js
    • It loads the configuration from the /demo/manual directory.
    • It generates a PDF named manual.pdf.
  2. Formal:

    • File: /demo/demo_formal.js
    • It loads the configuration from the /demo/formal directory.

✏️ Writing Your Content

Create your content in Markdown format. MakeBook supports standard Markdown syntax and extends it with additional features:

Inline Formatting

  • Bold and Italics: Use **bold** or _italics_ for styling text.
  • Code: Use backticks `code` for inline code snippets.
  • Links: [Link Text](https://example.com) creates a clickable link.
  • Automatic Replacements: Typographic enhancements like converting -- to em-dashes.

Blocks

  • Headings: Use #, ##, ###, and #### for headings.
  • Lists: Create ordered and unordered lists using -, *, or numbers.
  • Code Blocks: Wrap code with triple backticks for formatted code blocks.
  • Quotes: Use > for blockquotes.

Tables

Create tables using pipe | characters:

| Column 1 | Column 2 |
| -------- | -------- |
| Data 1   | Data 2   |

Automatic Numbering and TOC

  • Use \\() to insert automatic numbering for sections.
  • Insert a table of contents using the \\toc tag on a separate line.

Transclusion

Include content from other files or images:

  • Images: \\image(plant.png)
  • Include Files: \\include(other.md)

🎨 Customization

You can customize the appearance of your PDF by defining styles and fonts in the configuration. Override default styles or create new ones to match your branding.

Fonts

Specify custom fonts by providing paths to font files:

const fontRoboto = {
    normal: '**/Roboto-Regular.ttf',
    bold: '**/Roboto-Bold.ttf',
    italics: '**/Roboto-Italic.ttf'
};

book.font(fontRoboto);

Styles

Define styles for different elements:

const config = {
    styles: {
        h1: {
            fontSize: 26,
            bold: true,
            color: "#0000FF"
        },
        p: {
            fontSize: 12,
            lineHeight: 1.5
        }
    }
};

πŸ™ Acknowledgments

MakeBook utilizes the fantastic makepdf library to convert Markdown to PDF. Special thanks to its contributors for making PDF generation in Node.js a breeze!

πŸ“¬ Contact

For questions or suggestions, please open an issue in the GitHub repository or contact the project maintainer.

πŸ“„ License

The MIT License (MIT)

Copyright (c) Martin Clasen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.