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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pdfmake-markup-nunjucks

v1.0.0-beta

Published

Render .pdfmk.njk templates into pure pdfmake-markup using Nunjucks.

Downloads

7

Readme

pdfmake-markup-nunjucks

Render Nunjucks templates with a .pdfmk.njk extension into pure pdfmake-markup strings.

This package is intentionally small: it handles the templating pass only. The output is plain .pdfmk, which you can then pass to pdfmake-markup yourself.

It also tries hard not to get in Nunjucks' way. If you already have your own Environment, custom loaders, extensions, globals, filters, or custom tag syntax, you can keep using them by passing that environment into render.

Install

npm install pdfmake-markup-nunjucks nunjucks

For local development in this repo, pdfmake-markup is kept in devDependencies for tests and the sample runner.

Usage

const nunjucks = require('nunjucks');
const { render } = require('pdfmake-markup-nunjucks');
const { decode } = require('pdfmake-markup');

const template = `
{% set rows = [
  { name: "Alpha", value: 10 },
  { name: "Beta", value: 20 }
] %}
{
  content: [
    { text: "Invoice", bold: true, fontSize: 18 },
    ...map(row in %{ {{ rows | json }} }%) {
      { text: %{row.name + ": " + row.value}% }
    }
  ]
}
`;

const markup = render(template);
const docDefinition = decode(markup);

Using your own Nunjucks environment:

const env = new nunjucks.Environment(null, {
  autoescape: false,
  tags: {
    variableStart: '[[',
    variableEnd: ']]',
  },
});

env.addGlobal('companyName', 'ACME');

const markup = render('{ title: [[ companyName | json ]] }', {}, { env });

API

render(template: string, context?: object, options?: RenderOptions): string

Renders a .pdfmk.njk template string into pure .pdfmk.

createEnvironment(options?: EnvironmentOptions): nunjucks.Environment

Creates a Nunjucks environment and passes standard Nunjucks options through. By default it sets autoescape: false unless you override it, and adds the built-in json / literal filters.

Built-in filter

json

Serializes a value into a pdfmake-markup-friendly literal so it can be embedded safely into .pdfmk expressions.

literal

Alias of json.

{% set rows = [{ "name": "Alpha" }, { "name": "Beta" }] %}
...map(row in %{ {{ rows | json }} }%) {
  { text: %{row.name}% }
}

Render Options

interface EnvironmentOptions {
  loader?: nunjucks.ILoaderAny | nunjucks.ILoaderAny[] | null;
  loaderOptions?: nunjucks.FileSystemLoaderOptions;
  searchPaths?: string | string[];
  installBuiltins?: boolean;
  overwriteBuiltins?: boolean;
  configureEnvironment?: (env: nunjucks.Environment) => void;
}

interface RenderOptions extends EnvironmentOptions {
  env?: nunjucks.Environment;
}

If you want to render a file, read it yourself and pass the contents to render(). For relative {% include %} resolution, provide searchPaths or your own configured environment.

const fs = require('fs');
const path = require('path');
const { render } = require('pdfmake-markup-nunjucks');

const filePath = path.join(__dirname, 'invoice.pdfmk.njk');
const template = fs.readFileSync(filePath, 'utf8');

const markup = render(template, data, {
  searchPaths: path.dirname(filePath),
});

Samples

The repo ships the upstream pdfmake-markup samples under samples/*.pdfmk.njk, adjusted to use Nunjucks variables where that helps demonstrate the templating layer.

You can generate PDFs with:

npm run sample -- basics
npm run sample:all

License

MIT