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

@cley_faye/pdf-overlay

v3.0.0

Published

Add an overlay to all pages of a PDF

Downloads

8

Readme

@cley_faye/pdf-overlay

Add an overlay to all pages of a PDF.

This is a preliminary version; works as a CLI tool using Node.

Usage

You can use it without installation as long as NPM is available.

Pass the name of the config file as the only argument.

npx --package=@cley_faye/pdf-overlay <config file>

Configuration

The configuration must be provided in a JSON file with the following properties:

{
  "inputPDF": "input.pdf",
  "fileSource": "data.txt",
  "outputDirectory": "output",
  "filenameTemplate": "%{basename} - %{index} - %{text}",
  "overlay": [
    {
      "position": {"horizontal": "left", "vertical": "top"},
      "orientation": "horizontal",
      "textTemplate": "%{text}",
      "font": "Courier",
      "size": 12,
      "color": {"r": 0, "g": 0, "b": 0},
      "opacity": 1,
      "margin": 0,
      "pages": "all"
    },
    {
      "position": {"horizontal": "right", "vertical": "center"},
      "orientation": "vertical",
      "textTemplate": "Exemplaire %{index} / %{total}",
      "font": "Courier",
      "size": 12,
      "color": {"r": 0, "g": 0, "b": 0},
      "opacity": 1,
      "margin": 0
      "pages": "1"
    }
  ]
}

inputPDF

Name of the input PDF file.

fileSource

Name of the file containing all the "text" to use for overlay, one per line.

outputDirectory

Directory to put the overlaid files into. Optional, defaults to "output".

filenameTemplate

Template for the output filename. See the "Template string" section below for more details. Optional, defaults to "%{basename} - %{index} - %{text}".

overlay

Describe the overlays to apply to each pages. This property is an array and each entry is a single overlay text.

position

Position of the overlay. It is possible to specify a position in two ways:

  • absolute position, starting from the bottom-left corner of a page: {"x": 50, "y": 50} (x is the horizontal offset, y the vertical one)
  • relative to a page's edge: {"horizontal": "left", "vertical": "top"}

For the edge-based position, the valid values for horizontal are:

  • "left"
  • "center"
  • "right"

The valid values for vertical are:

  • "top"
  • "center"
  • "bottom"

textTemplate

The text to stamp with this overlay. See the "Template string" section below for more details.

font

Font for the text. Can be one of the standard PDF font:

  • "Courier"
  • "CourierBold"
  • "CourierOblique"
  • "CourierBoldOblique"
  • "Helvetica"
  • "HelveticaBold"
  • "HelveticaOblique"
  • "HelveticaBoldOblique"
  • "TimesRoman"
  • "TimesRomanBold"
  • "TimesRomanItalic"
  • "TimesRomanBoldItalic"
  • "Symbol"
  • "ZapfDingbats"

Alternatively, it is possible to pass the path to a font file. Optional, defaults to "Courier".

orientation

Change the orientation of the text. Possible values:

  • "horizontal" (default value): text is horizontal
  • "horizontalFlip": text is flipped 180°
  • "vertical": text is vertical, rotated 90° clockwise from horizontal
  • "verticalFlip": text is vertical, rotated 90° counterclockwise from horizontal

size

Font size. Optional, defaults to 12.

color

Color for the text. Must be provided as a triple with r for red, g for green and b for blue. Values goes from 0 to 1. Optional, defaults to black.

opacity

Text opacity. Range from 0 to 1. Optional, defaults to 1 (full opacity).

margin

Margin to add between the text and the page border. The unit is… let's say points. Optional, defauls to 0.

pages

Pages to put the overlay on. Defaults to all pages if not specified.

To define which page will get this specific overlay, you can use directives, which will be applied in the provided order. Each directives are separated by a semicolon.

Available directives:

  • all: enable on all pages
  • odd: enable on odd pages
  • even: enable on even pages
  • 3: enable on page 3 (any page number)
  • -3: disable on page 3 (any page number)
  • 4,7: enable on pages 4 to 7 (included)
  • -4,7: disable on pages 4 to 7 (included)

Some examples:

  • all;-10: enable on all pages except page 10
  • odd;-11: enable on all odd pages except page 11
  • even;3;-22,36: enable on all even pages plus page 3, except pages from 22 to 36
  • 34: enable only on page 34
  • 34,1664;-63: enable on pages from 34 to 1664 (included), except on page 63

Template string

For both the filename and the textTemplate properties in configuration, you can specify template variables. To do so, use this notation: %{variable name}.

Available variables:

  • index: ID of the current output (starts at 1)
  • total: total number of files that will be produced
  • text: the line of text from the data source
  • basename: the name of the input PDF file

The following string is a working example:

For %{text}, edition %{index} of %{total}