Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

letter-press

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

letter-press

Print GitHub Markdown to PDF using headless Chrome.

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

letter-press

Print GitHub Markdown to PDF using headless Chrome.

Example

Print letter.md to dist/letter.pdf then log a completion message.

const letterpress = require('letter-press')
const letter = fs.readFileSync(path.join(__dirname, 'letter.md'))

letterpress.print('letter', letter)
  .then(() => console.log('🐈  done'))
Example: Print multiple letters using a template

Print letters to dist/*.pdf based on a Markdown template and some data (e.g. mailing list).

const letterpress = require('letter-press')

const letter = (sender, recipient) =>
`Dear ${recipient},

Here is some **bold text**. *Winky face*.

Yours sincerely,
${sender}
`
const list = [
  { id: 'letter1', sender: 'Your Secret Lesbian Admirer', recipient: 'John' }
  // ...
];

(async () => {
  const press = await letterpress.launch()

  const jobs = []
  list.forEach(item => {
    const markdown = letter(item.sender, item.recipient)
    const job = press.print(item.id, markdown)
    jobs.push(job)
  })

  await Promise.all(jobs)
  press.close()
})()

API

letterpress.print(id, markdown, [opts])

Print the given markdown string to PDF. Return: Promise

Writes the following files:
dist/id.html
dist/id.pdf

letterpress.launch([opts])

Launch a new Press. Return: Promise of Press

Press.prototype.print(id, markdown, [opts])

Print the given markdown string to PDF. Return: Promise of Press

Writes the following files:
dist/id.html
dist/id.pdf

The returned Promise resolves with the Press object so that prints can easily be chained together with .then.

Press.prototype.close()

Close this Press. Call after all prints have resolved.

Options

These options have nice defaults but can be entirely overridden.

opts.path Path to output folder. Default: dist

opts.quiet Only log errors. Default: false

opts.template Path to pug template file used when generating HTML. The template must contain a !=content, and may contain a !=title. Default: Template File

opts.markdown Options passed to markdown-it new MarkdownIt(opts). API

opts.pdf Options passed to puppeteer page.pdf(opts). API

Keywords

FAQs

Package last updated on 14 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc