Skip to content

About

Data-driven client-side printing: print regions, redact, auto-blank PII, crop marks, draw-to-print. Zero dependencies.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

101 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@simtabi/printcraft

npm Tests Static analysis License MIT

Client-side printing you can aim: real paginated sheets with numbers and borders, a region tool that prints what you drew, redaction that is verified rather than hoped for, and a right-click menu, command palette and keyboard commands that are there the moment the script loads.

Runs in any browser with afterprint and document.fonts: Chrome, Edge, Firefox and Safari, current and two back. TypeScript source, two runtime dependencies (both leaf), ESM + UMD builds, and a command line for CI.

Try the demo: every job, the interaction layer and the inspector, with nothing to install.

Install

npm install @simtabi/printcraft

3.0.0 is on npm. Releases after it are published to GitHub Packages while npm's trusted publishing cannot take a publish from this repository (npm/cli#9969). GitHub Packages asks for a token even for a public package, so to install one, add a GitHub token with read:packages to the project's .npmrc first:

@simtabi:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}

See npm or GitHub Packages.

import Printcraft from '@simtabi/printcraft'; // esm
const Printcraft = require('@simtabi/printcraft'); // cjs (umd build)

Or a script tag. The UMD build sets a Printcraft global and boots the declarative layer automatically:

<script src="printcraft.umd.js"></script>
<button data-printcraft="#invoice">Print</button>

Quick start guide and usage

Getting started

Nothing to configure: once the module is imported (or the UMD script is loaded), Printcraft is ready to print. Two optional script-tag attributes control the UMD auto-boot:

  1. data-auto-init="false" skips the auto-boot entirely.
  2. data-config="/printcraft.config.json" fetches page-wide defaults from a file.

Usage

const job = await Printcraft.print('#invoice');
console.log(job.status, job.duration + 'ms');
await Printcraft.print({
  target: '#invoice',
  excludeSelectorList: ['.ads', 'nav'],
  headerText: 'ACME CO',
  setPrintSize: 'A4 portrait',
  pageMargin: '18mm'
});
await Printcraft.job('#invoice').exclude('.ads').redact('.ssn').watermark('DRAFT', 0.15).print();

The full walkthrough is in Getting started; everything else is in the documentation index.

Documentation

Full documentation: https://opensource.simtabi.com/documentation/simtabi/printcraft-js/

Guides

  • Installation — package, script tag, and build output
  • Demo — where to run it, and how its assets are built
  • Getting started — your first job, in each of the three surfaces
  • Surfaces — imperative, declarative, and JSON config
  • Configuration — page defaults, config files, content annotations
  • Architecture — the pipeline, the module layout, and why it is shaped this way
  • Pagination — real sheets, page numbers, borders and running bands
  • The proof sheet — see the assembled document before it prints
  • Cover and notes pages — the title at the front, every mark listed at the back
  • Security — the threat model, and what redaction guarantees
  • Print backends — sending a job to a server or a companion service
  • Comparison — lineage from ezPrintJS, and what changed
  • Release — versioning and the publish process

Reference

Recipes

Community

Questions and ideas belong in GitHub Discussions; bugs in Issues.

Contributing & security

See CONTRIBUTING.md for local setup and conventions, and SECURITY.md to report a vulnerability privately.

License

MIT. A clean-room reimplementation and extension of the public API of ezPrintJS v1.1.0 (2017); no code from that commercial library was used. Icon artwork from Tabler Icons (MIT).

About

Data-driven client-side printing: print regions, redact, auto-blank PII, crop marks, draw-to-print. Zero dependencies.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages