Skip to content

Utility for generating images of lightly modified webpages

License

Notifications You must be signed in to change notification settings

chromakode/typesetters-son

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typesetter's Son

npm license

Named for "Typesetter's Son" on Channel101

Typesetter's Son is a small utility for generating images and PDFs based on lightly modified webpages. It loads a URL in Headless Chrome, substitutes innerHTML for elements you specify, and takes a screenshot.

It works great on SVGs too -- just sprinkle in id attributes where you want to modify text!

Installation

Library: npm install typesetters-son
Executable: npm install -g typesetters-son

Example:

typesetters-son http://dogpatchjs.com/banner -o dogpatch.png -w 1024 -c 'body' -s '{"#day": "Monday, July 17, 2017", "#where": "Spark Social", "#time": "6:30pm"}'

typesetters-son http://dogpatchjs.com/banner -o dogpatch.pdf -p Letter -s '{"#day": "Monday, July 17, 2017", "#where": "Spark Social", "#time": "6:30pm"}'

Example output

Library Usage

const {generateImage} = require('typesetters-son')
generateImage({
  url: 'http://dogpatchjs.com/banner',
  output: 'dogpatch.png',
  width: 1024,
  height: 800,
  density: 1,  // defaults to 1 if unspecified
  crop: 'body',
  subs: {
   '#day': new Date().toDateString(),
   '#where': 'Spark Social',
   '#time': '6:30pm',
  },
})

const {generatePDF} = require('typesetters-son')
generatePDF({
  url: 'http://dogpatchjs.com/banner',
  output: 'dogpatch.pdf',
  paper: 'Letter',
  removeBackground: false,
  subs: {
   '#day': new Date().toDateString(),
   '#where': 'Spark Social',
   '#time': '6:30pm',
  },
})

Executable Usage

Usage: typesetters-son URL -o [path]

Options:
  --output, -o   output image/pdf path                                [required]
  --width, -w    viewport width                                   [default: 800]
  --height, -h   viewport height                                  [default: 600]
  --crop, -c     element query to crop around
  --density, -d  pixel density                                      [default: 1]
  --paper, -p    paper size (e.g. Letter, A4, etc.)          [default: "Letter"]
  --remove-bg    remove bg colors (for printing)      [boolean] [default: false]
  --subs, -s     text substitutions (JSON)

About

Utility for generating images of lightly modified webpages

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published