Socket
Socket
Sign inDemoInstall

electron-md-to-pdf

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-md-to-pdf

Convert Markdown to PDF in Electron apps


Version published
Weekly downloads
4
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

electron-md-to-pdf

Convert Markdown to PDF in Electron apps

This simple library first converts a Markdown string to HTML (using Showdown) and then to PDF (using Chromium's built-in print functionality). This makes it possible to convert Markdown to PDF with a minimal number of dependencies in Electron apps.

Installation

npm install electron-md-to-pdf

Usage

This module exposes two functions:

  • mdToPdfBuffer(md, options), which generates a PDF from the provided Markdown string (md) and returns it as a Buffer
  • mdToPdfFile(md, filePath, options), which generates a PDF from the provided Markdown string and saves it at the provided filePath

Both functions return promises.

The options parameter is optional. It's an object which may contain the following values:

  • basePath (String): Base directory for relative paths of resources, e.g. images. Default: Current directory
  • cssString (String): CSS string to inject into the HTML which is generated from the Markdown string (e.g. "body { color: red; }")
  • cssFiles (String array): Array of CSS files to inject into the HTML (e.g. ["./path/to/styles.css"])
  • mdFlavor (String): Markdown flavor to use, one of ["original", "vanilla", "github"] (see the Showdown docs). Default is "github"
  • pdfOptions (Object): Options to pass to Electron's PDF print function (see the Electron docs)
  • showdownOptions (Object): Other options for the HTML generation (see the Showdown docs)
  • wrapperClasses (String): Class(es) to apply to the wrapper div around the Markdown HTML

See the examples on how to use the module in the main process and renderer process.

Development

Make sure you have Node.js and Yarn installed.

  1. Clone this repo: git clone REPO_URL
  2. Install the dependencies: yarn
  3. Run the test app: yarn start

Contributing

Suggestions and contributions are always welcome! Please first discuss changes via issue before submitting a pull request.

Keywords

FAQs

Package last updated on 01 Jan 2020

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