npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

d3-save-pdf

v0.0.3

Published

D3 plugin for exporting SVGs. Based on svg-crowbar by Shan Carter

Downloads

159

Readme

d3-save-pdf

A fork of the nytimes d3-save-svg bookmarklet that extracts SVG nodes and accompanying styles from an HTML document and downloads them as an SVG file --- A file which you could open and edit in Adobe Illustrator, for instance. Because SVGs are resolution independent, it’s great for when you want to use web technologies to create documents that are meant to be printed (like, maybe on newsprint). It was created with d3.js in mind, but it should work fine no matter how you choose to generate your SVG.

Differences from the bookmarklet

  • Can use to download specific svg as pdf, which can be incorporated into buttons for exporting images.
  • Allows specification of custom file names.
  • Handles embedded raster images.
  • Has convenience method for embedding raster images.

Note

Most of this has been cobbled together from stackoverflow and issues logged on the nytimes svg-crowbar repo.

API

save(svgElement, config)

Given a SVG element and an optional configuration object, save embeds external CSS styling and downloads the pdf file. The filename will be (in order of existence) the svgElement ID, the svgElement class, or the window title. Optionally, you can specify the filename in the config object such that config.filename will be the name of the downloaded file.

d3.select('button#export').on('click', function() {
  var config = {
    filename: 'customFileName',
  }
  d3_save_pdf.save(d3.select('svg').node(), config);
});

embedRasterImages(svgElement)

A convenience function for converting all referenced raster images in an SVG element to base64 data via data URI, so that it is embedded in the SVG.then It is saved as pdf This ensures that the downloaded image will contain the raster image. Probably should be updated to just directly convert a referenced link to data URI instead of doing it in two separate steps.

svg
  .append('g')
   .append('image')
      .attr('xlink:href', 'assets/test.png')
      .attr("width", 100)
      .attr("height", 100)
      .attr("x", (width / 2)  - 50)
      .attr("y", (height / 6) * 5);

d3_save_pdf.embedRasterImages(svg.node());

Contributing

npm install to get the development dependencies, test and build.

Testing is via Tape and jsdom. Right now the tests are pretty rudimentary. Also index.html serves as a good check on whether things are working.

Development is done using the git-flow workflow. Please merge changes into the develop branch.

See CONTRIBUTING.md for additional information.