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

canvas2pdf

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas2pdf

Export an HTML canvas to PDF

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
128
increased by16.36%
Maintainers
1
Weekly downloads
 
Created
Source

Canvas2PDF

Canvas2PDF exports an HTML canvas to PDF. In other words, this library lets you build an PDF document using the canvas API.

How it works

We create a mock 2d canvas context. Use the canvas context like you would on a normal canvas. As you call methods, we use PDFKit to generate a PDF document.

Usage

//Create a new PDF canvas context.
var ctx = new canvas2pdf.Context(blobStream());

//draw your canvas like you would normally
ctx.fillStyle='yellow';
ctx.fillRect(100,100,100,100);
// more canvas drawing, etc...

//convert your PDF to a Blob and save to file
context.stream.on('finish', function () {
    var blob = context.stream.toBlob('application/pdf');
    saveAs(blob, 'example.pdf', true);
});
context.end();

Dependencies

  • PDFKit
  • blob-stream required when using in a web browser.

Using with node.js

canvas2pdf works with node.js. Note that neither a DOM or canvas library is needed.

Interactive Browser Demo

https://joshua-gould.github.io/canvas2pdf/

Notes

  • Inspired by Canvas2Svg
  • Some canvas 2d context methods are not implemented yet (e.g. setTransform and arcTo).

License

MIT

Keywords

FAQs

Package last updated on 16 Aug 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