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

@lachie-pdf/render

v3.2.1

Published

A render engine for Node and the browser

Downloads

2

Readme

@lachie-pdf/render

React-pdf render engine

How to install

yarn add @lachie-pdf/render

How it works

const render = require('@lachie-pdf/render');
const primitives = require('@lachie-pdf/primitives');

const view = {
  type: primitives.View,
  style: {
    backgroundColor: 'red',
    borderTopLeftRadius: 5,
    borderTopRightRadius: 10,
    borderBottomLeftRadius: 0,
    borderBottomRightRadius: 15,
    borderTopColor: 'yellow',
    borderLeftColor: 'green',
    borderBottomColor: 'black',
    borderRightColor: 'purple',
  },
  box: {
    left: 20,
    top: 20,
    width: 100,
    height: 80,
    borderTopWidth: 3,
    borderLeftWidth: 2,
    borderBottomWidth: 1,
    borderRightWidth: 4,
  },
};

const doc = {
  type: primitives.Document,
  children: [
    {
      type: primitives.Page,
      box: { width: 400, height: 600 },
      children: [view],
    },
  ],
};

// Provide your own context
const ctx = createContext();

render.default(ctx, doc);

This library exports a render function that takes two arguments:

  • ctx: This is the target context where the document is going to be rendered. React-pdf currently uses a pdfkit document as context, but it can target any other type of structure as long as it signature matches pdfkit API. In the future this will enable rendering documents into muliple formats in addition to PDF.
  • node: Document root node. A node is a nested structure that defines a single element in a document. They are defined by it's type and arguments.

Node structure

A node represents a single element inside a document. It's mainly defined by it's type (mandatory) field in addition to other values to define where that element is positioned inside the document (box), how it looks (style), how it should behave (params) and what sub-nodes it contains (children).

The root node must always be of type DOCUMENT, containing as many PAGE nodes as desired inside it's children field.

Bare in mind this package does not handle any type of node positioning, inheritance, style transformations or any other layout related logic. It's role is limited to render exactly the node it get's into the provided context. Take this into account when definig styles as paddingTop, paddingLeft and so on instead of the shortcut padding. For layout or styles transformation this project provides separate packages.

node.type

Mandatory field specifiying the type of the particular node. The full list of types can be found and imported from @lachie-pdf/primitives

node.box

Defines bounding box where a particular node is located inside a document

  • left
  • top
  • width
  • height
  • paddingTop
  • paddingLeft
  • paddingBottom
  • paddingRight
  • marginTop
  • marginLeft
  • marginBottom
  • marginRight
  • borderTopWidth
  • borderLeftWidth
  • borderBottomWidth
  • borderRightWidth

node.style

Defines how the node looks like. There are some types of nodes that expect special style values, but generally all support:

  • color
  • opacity
  • overflow
  • backgroundColor
  • borderTopLeftRadius
  • borderTopRightRadius
  • borderBottomLeftRadius
  • borderBottomRightRadius
  • borderTopColor
  • borderLeftColor
  • borderBottomColor
  • borderRightColor
  • others...

node.props

Specific node params needed to render correctly ot behave like certain way. Specially needed for SVG nodes

PDF example

const fs = require('fs');
const render = require('@lachie-pdf/render');
const pdfkit = require('@lachie-pdf/pdfkit');

const PDFDocument = pdfkit.default;

const ctx = new PDFDocument({ autoFirstPage: false });

const doc = {}; // See above

render.default(ctx, doc);

const stream = fs.createWriteStream('./test.pdf');

ctx.pipe(stream);

License

MIT © Diego Muracciole