{"id":13485839,"url":"https://github.com/alanshaw/markdown-pdf","last_synced_at":"2025-05-14T04:09:13.878Z","repository":{"id":8514616,"uuid":"10127525","full_name":"alanshaw/markdown-pdf","owner":"alanshaw","description":" :page_facing_up: Markdown to PDF converter","archived":false,"fork":false,"pushed_at":"2023-10-19T06:34:40.000Z","size":422,"stargazers_count":2769,"open_issues_count":91,"forks_count":256,"subscribers_count":37,"default_branch":"master","last_synced_at":"2025-05-11T21:21:04.997Z","etag":null,"topics":["converter","markdown","md","pdf","pdf-generation","template"],"latest_commit_sha":null,"homepage":"https://npmjs.org/package/markdown-pdf","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alanshaw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2013-05-17T16:29:42.000Z","updated_at":"2025-05-11T14:35:53.000Z","dependencies_parsed_at":"2024-01-03T07:03:58.958Z","dependency_job_id":"c2c23dba-69f3-4f79-aae4-e092bd1c844a","html_url":"https://github.com/alanshaw/markdown-pdf","commit_stats":{"total_commits":151,"total_committers":22,"mean_commits":6.863636363636363,"dds":0.5364238410596027,"last_synced_commit":"3b8e2070aa88460f8932f3cbcb900b6a181a5510"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanshaw%2Fmarkdown-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanshaw%2Fmarkdown-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanshaw%2Fmarkdown-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanshaw%2Fmarkdown-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alanshaw","download_url":"https://codeload.github.com/alanshaw/markdown-pdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254070020,"owners_count":22009559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["converter","markdown","md","pdf","pdf-generation","template"],"created_at":"2024-07-31T18:00:32.363Z","updated_at":"2025-05-14T04:09:08.840Z","avatar_url":"https://github.com/alanshaw.png","language":"JavaScript","funding_links":[],"categories":["Markdown","JavaScript","Tools","Converters","Generators","Markdown Building Blocks"],"sub_categories":["Converters","Markdown to Portable Document Format (PDF)"],"readme":"markdown-pdf [![Build Status](https://travis-ci.org/alanshaw/markdown-pdf.svg)](https://travis-ci.org/alanshaw/markdown-pdf) [![Dependency Status](https://david-dm.org/alanshaw/markdown-pdf.svg)](https://david-dm.org/alanshaw/markdown-pdf) [![Coverage Status](https://img.shields.io/coveralls/alanshaw/markdown-pdf.svg?style=flat)](https://coveralls.io/r/alanshaw/markdown-pdf?branch=master)\n===\n\nNode module that converts Markdown files to PDFs.\n\nThe 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.\n\n## Install\n\n```sh\nnpm install -g markdown-pdf --ignore-scripts\n```\n\nNote: elevated (sudo) permissions may be needed for `npm install -g`\n\n## Usage\n\n```\nUsage: markdown-pdf [options] \u003cmarkdown-file-path\u003e\n\nOptions:\n\n  -h, --help                             output usage information\n  -V, --version                          output the version number\n  \u003cmarkdown-file-path\u003e                   Path of the markdown file to convert\n  -c, --cwd [path]                       Current working directory\n  -p, --phantom-path [path]              Path to phantom binary\n  -h, --runnings-path [path]             Path to runnings (header, footer)\n  -s, --css-path [path]                  Path to custom CSS file\n  -z, --highlight-css-path [path]        Path to custom highlight-CSS file\n  -m, --remarkable-options [json]        Options to pass to Remarkable\n  -f, --paper-format [format]            'A3', 'A4', 'A5', 'Legal', 'Letter' or 'Tabloid'\n  -r, --paper-orientation [orientation]  'portrait' or 'landscape'\n  -b, --paper-border [measurement]       Supported dimension units are: 'mm', 'cm', 'in', 'px'\n  -d, --render-delay [millis]            Delay before rendering the PDF\n  -t, --load-timeout [millis]            Timeout before the page is rendered in case `page.onLoadFinished` isn't fired\n  -o, --out [path]                       Path of where to save the PDF\n```\n\n`markdown-pdf` can also be used programmatically:\n\n```javascript\nvar markdownpdf = require(\"markdown-pdf\")\n  , fs = require(\"fs\")\n\nfs.createReadStream(\"/path/to/document.md\")\n  .pipe(markdownpdf())\n  .pipe(fs.createWriteStream(\"/path/to/document.pdf\"))\n\n// --- OR ---\n\nmarkdownpdf().from(\"/path/to/document.md\").to(\"/path/to/document.pdf\", function () {\n  console.log(\"Done\")\n})\n```\n\n### Options\n\nPass an options object (`markdownpdf({/* options */})`) to configure the output.\n\n#### options.cwd\nType: `String`\nDefault value: `process.cwd()`\n\nCurrent working directory.\n\n#### options.phantomPath\nType: `String`\nDefault value: Path provided by phantomjs module\n\nPath to the phantomjs binary.\n\n#### options.cssPath\nType: `String`\nDefault value: `[module path]/markdown-pdf/css/pdf.css`\n\nPath to custom CSS file, relative to the current directory.\n\n#### options.highlightCssPath\nType: `String`\nDefault value: `[module path]/markdown-pdf/css/highlight.css`\n\nPath to custom highlight CSS file (for code highlighting with [highlight.js](https://highlightjs.org)), relative to the current directory.\n\n#### options.paperFormat\nType: `String`\nDefault value: `A4`\n\n'A3', 'A4', 'A5', 'Legal', 'Letter' or 'Tabloid'.\n\n#### options.paperOrientation\nType: `String`\nDefault value: `portrait`\n\n'portrait' or 'landscape'.\n\n#### options.paperBorder\nType: `String`\nDefault value: `2cm`\n\nSupported dimension units are: 'mm', 'cm', 'in', 'px'\n\n#### options.runningsPath\nType: `String`\nDefault value: `runnings.js`\n\nPath to CommonJS module which sets the page header and footer (see [runnings.js](runnings.js)).\n\n#### options.renderDelay\nType: `Number`\nDefault value: Time until [`page.onLoadFinished`](http://phantomjs.org/api/webpage/handler/on-load-finished.html) event fired\n\nDelay (in ms) before the PDF is rendered.\n\n#### options.loadTimeout\nType: `Number`\nDefault value: `10000`\n\nIf `renderDelay` option isn't set, this is the timeout (in ms) before the page is rendered in case the `page.onLoadFinished` event doesn't fire.\n\n#### options.preProcessMd\nType: `Function`\nDefault value: `function () { return through() }`\n\nA function that returns a [through2 stream](https://npmjs.org/package/through2) that transforms the markdown before it is converted to HTML.\n\n#### options.preProcessHtml\nType: `Function`\nDefault value: `function () { return through() }`\n\nA function that returns a [through2 stream](https://npmjs.org/package/through2) that transforms the HTML before it is converted to PDF.\n\n#### options.remarkable\nType: `object`\nDefault value: `{ breaks: true }`\n\nA config object that is passed to [remarkable](https://www.npmjs.com/package/remarkable#options), the underlying markdown parser.\n\n##### options.remarkable.preset\nType: `String`\nDefault value: `default`\n\nUse remarkable [presets](https://www.npmjs.com/package/remarkable#presets) as a convenience to quickly enable/disable active syntax rules and options for common use cases.\n\nSupported values are `default`, `commonmark` and `full`\n\n##### options.remarkable.plugins\nType: `Array` of remarkable-plugin `Function`s\nDefault value: `[]`\n\nAn array of Remarkable plugin functions, that extend the markdown parser functionality.\n\n##### options.remarkable.syntax\nType: `Array` of optional remarkable syntax `Strings`s\nDefault value: `[]`\n\nAn array of [optional Remarkable syntax extensions](https://github.com/jonschlinkert/remarkable#syntax-extensions), disabled by default, that extend the markdown parser functionality.\n\n## API\n\n### from.path(path, opts) / from(path, opts)\n\nCreate a readable stream from `path` and pipe to markdown-pdf. `path` can be a single path or array of paths.\n\n### from.string(string)\n\nCreate a readable stream from `string` and pipe to markdown-pdf. `string` can be a single string or array of strings.\n\n### concat.from.paths(paths, opts)\n\nCreate and concatenate readable streams from `paths` and pipe to markdown-pdf.\n\n### concat.from.strings(strings, opts)\n\nCreate and concatenate readable streams from `strings` and pipe to markdown-pdf.\n\n### to.path(path, cb) / to(path, cb)\n\nCreate a writeable stream to `path` and pipe output from markdown-pdf to it. `path` can be a single path, or array of output paths if you specified an array of inputs. The callback function `cb` will be invoked when data has finished being written.\n\n### to.buffer(opts, cb)\n\nCreate a [concat-stream](https://npmjs.org/package/concat-stream) and pipe output from markdown-pdf to it. The callback function `cb` will be invoked when the buffer has been created.\n\n### to.string(opts, cb)\n\nCreate a [concat-stream](https://npmjs.org/package/concat-stream) and pipe output from markdown-pdf to it. The callback function `cb` will be invoked when the string has been created.\n\n## More examples\n\n### From string to path\n\n```javascript\nvar markdownpdf = require(\"markdown-pdf\")\n\nvar md = \"foo===\\n* bar\\n* baz\\n\\nLorem ipsum dolor sit\"\n  , outputPath = \"/path/to/doc.pdf\"\n\nmarkdownpdf().from.string(md).to(outputPath, function () {\n  console.log(\"Created\", outputPath)\n})\n```\n\n### From multiple paths to multiple paths\n\n```javascript\nvar markdownpdf = require(\"markdown-pdf\")\n\nvar mdDocs = [\"home.md\", \"about.md\", \"contact.md\"]\n  , pdfDocs = mdDocs.map(function (d) { return \"out/\" + d.replace(\".md\", \".pdf\") })\n\nmarkdownpdf().from(mdDocs).to(pdfDocs, function () {\n  pdfDocs.forEach(function (d) { console.log(\"Created\", d) })\n})\n```\n\n### Concat from multiple paths to single path\n\n```javascript\nvar markdownpdf = require(\"markdown-pdf\")\n\nvar mdDocs = [\"chapter1.md\", \"chapter2.md\", \"chapter3.md\"]\n  , bookPath = \"/path/to/book.pdf\"\n\nmarkdownpdf().concat.from(mdDocs).to(bookPath, function () {\n  console.log(\"Created\", bookPath)\n})\n```\n\n### Transform markdown before conversion\n\n```javascript\nvar markdownpdf = require(\"markdown-pdf\")\n  , split = require(\"split\")\n  , through = require(\"through\")\n  , duplexer = require(\"duplexer\")\n\nfunction preProcessMd () {\n  // Split the input stream by lines\n  var splitter = split()\n\n  // Replace occurences of \"foo\" with \"bar\"\n  var replacer = through(function (data) {\n    this.queue(data.replace(/foo/g, \"bar\") + \"\\n\")\n  })\n\n  splitter.pipe(replacer)\n  return duplexer(splitter, replacer)\n}\n\nmarkdownpdf({preProcessMd: preProcessMd})\n  .from(\"/path/to/document.md\")\n  .to(\"/path/to/document.pdf\", function () { console.log(\"Done\") })\n```\n\n### Remarkable options and plugins\n\nExample using [remarkable-classy](https://www.npmjs.com/package/remarkable-classy) plugin:\n\n```javascript\nvar markdownpdf = require(\"markdown-pdf\")\n\nvar options = {\n    remarkable: {\n        html: true,\n        breaks: true,\n        plugins: [ require('remarkable-classy') ],\n\t\tsyntax: [ 'footnote', 'sup', 'sub' ]\n    }\n}\n\nmarkdownpdf(options)\n  .from(\"/path/to/document.md\")\n  .to(\"/path/to/document.pdf\", function () { console.log(\"Done\") })\n```\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/alanshaw/markdown-pdf/issues/new) or submit PRs.\n\n## License\n\n[MIT](LICENCE) © Alan Shaw\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanshaw%2Fmarkdown-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falanshaw%2Fmarkdown-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanshaw%2Fmarkdown-pdf/lists"}