GithubHelp home page GithubHelp logo

nvdnkpr / markdown-pdf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alanshaw/markdown-pdf

0.0 2.0 0.0 325 KB

Markdown to PDF converter

Home Page: https://npmjs.org/package/markdown-pdf

License: MIT License

markdown-pdf's Introduction

markdown-pdf Build Status Dependency Status Coverage Status

Node module that converts Markdown files to PDFs.

The PDF looks great because it is styled by HTML5 Boilerplate. What? - Yes! Your Markdown is first converted to HTML, then pushed into the HTML5 Boilerplate index.html. Phantomjs renders the page and saves it to a PDF. You can even customise the style of the PDF by passing an optional path to your CSS and you can pre-process your markdown file before it is converted to a PDF by passing in a pre-processing function, for templating.

Getting started

npm install markdown-pdf

Example Usage

Pass markdown-pdf a path to a markdown document or an array of paths and you'll be given back a path or an array of paths to temporary files that contain your converted PDFs.

var markdownpdf = require("markdown-pdf")
  , fs = require("fs")

markdownpdf("/path/to/document.md", function (er, pdfPath) {
  if (er) return console.error(er)
  
  // Move the pdf from the tmp path to where you want it
  fs.rename(pdfPath, "/path/to/document.pdf", function() {
    console.log("done")
  })
})

Options

Pass options to markdown-pdf like so:

var markdownpdf = require("markdown-pdf")
  , opts = {/* options */}

markdownpdf("/path/to/document.md", opts, function (er, pdfs) {})

options.phantomPath

Type: String Default value: Path provided by phantomjs module

Path to phantom binary

options.concatFiles

Type: Boolean Default value: false

If set to true, a single PDF will be created containing the contents of all of the Markdown files.

options.cssPath

Type: String Default value: ../pdf.css

Path to custom CSS file, relative to the current working directory

options.paperFormat

Type: String Default value: A4

'A3', 'A4', 'A5', 'Legal', 'Letter' or 'Tabloid'

options.paperOrientation

Type: String Default value: portrait

'portrait' or 'landscape'

options.paperBorder

Type: String Default value: 1cm

Supported dimension units are: 'mm', 'cm', 'in', 'px'

options.renderDelay

Type: Number Default value: 1000

Delay in millis before rendering the PDF (give HTML and CSS a chance to load)

options.preProcessMd

Type: Function Default value: null

Function to call before Markdown is converted to HTML. It is passed the Markdown file contents and must return a string

options.preProcessHtml

Type: Function Default value: null

Function to call after Markdown has been converted to HTML but before it is converted to PDF. It is passed the Markdown file contents and must return a string

CLI Interface

Installation

To use markdown-pdf as a standalone program from the terminal run

npm install -g markdown-pdf

Usage

Usage: markdown-pdf [options] <markdown-file-path>

Options:

  -h, --help                             output usage information
  -V, --version                          output the version number
  <markdown-file-path>                   Path of the markdown file to convert
  -p, --phantom-path [path]              Path to phantom binary
  -s, --css-path [path]                  Path to custom CSS file
  -f, --paper-format [format]            'A3', 'A4', 'A5', 'Legal', 'Letter' or 'Tabloid'
  -r, --paper-orientation [orientation]  'portrait' or 'landscape'
  -b, --paper-border [measurement]       Supported dimension units are: 'mm', 'cm', 'in', 'px'
  -d, --render-delay [millis]            Delay before rendering the PDF (give HTML and CSS a chance to load)
  -o, --out [path]                       Path of where to save the PDF

markdown-pdf's People

Contributors

alanshaw avatar alexwhitman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.