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

yapdfkitwrapper

v0.1.5

Published

Yet Another (FEATURE INCOMPLETE) PDFKit Wrapper.

Downloads

7

Readme

yapdfkitwrapper

Yet Another PDFKit Wrapper.

A node module to generate a PDF from plain javascript object. It uses PDFKit. It is very feature incomplete, till now I only implemented the features I needed myself. But still it might be helpful to someone so I wanted to publish it.

Features

  • Create PDF document with some text
  • Define a background image that will be placed on all the pages
  • Define a header and footer with page numbers
  • Simple API

Installing

npm install yapdfkitwrapper --save

Usage

Load as in the following example. Then use print() function as described in the next section.

var yapdfkitwrapper = require('yapdfkitwrapper');

Print

Printing a document is easy. The options listed below are shown with their defaults. You only need to set them if the default should be changed.

You can use the test/test.js file to generate a PDF quickly.

var doc = {
  options: {
    subject: '', // used as file property
    author: '', // used as file property
    size: 'a4',
    margins: { // in PDF points
      top: 141,
      bottom: 128,
      left: 72,
      right: 57
    },
    font: 'Helvetica',
    fontSize: 10,
    fillColor: 'black',
    align: 'left',
    background: fs.readFileSync('./logo.png') // or just background: './logo.png', default: no background
  },
  content: [
    {
      font: 'Helvetica',
      fontSize: '10',
      fillColor: 'black',
      align: 'left',
      text: 'Some text using the default layout'
    },
    {
      font: 'Courier',
      fontSize: '16',
      fillColor: 'white',
      align: 'right',
      position: { // in PDF points
        x: 250,
        y: 250
      },
      text: 'Some text with changed layout and postion'
    }
  ],
  header: {
    content: [
      {
        font: 'Helvetica',
        fontSize: '8',
        fillColor: 'grey',
        position: {
          x: 72,
          y: 100
        },
        align: 'left',
        text: 'Header with default layout and position'
      }
    ]
  },
  footer: {
    content: [
      {
        font: 'Helvetica',
        fontSize: '8',
        fillColor: 'grey',
        position: {
          x: 72,
          y: 'height - 100' // evaluated with current page height, can also be fixed no.
        },
        align: 'left',
        text: 'Footer with default layout and position'
      },
      {
        align: 'right',
        text: 'Page {page} of {pages}' // is replaced by current page and total page count
      }
    ]
  }
};

var stream = fs.createWriteStream('./test.pdf');
yapdfkitwrapper.print(doc, stream, function(err, result) {
  console.log(result); // e.g. prints {pages: 2}
}); // file can be found as ./test.pdf

Here is the result

Tests

No automated tests available but tested!

Unsupported

A lot of PDFKit features are not yet supported, contributions welcome!