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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@finum/html-to-pdf-to-sign

v0.1.1

Published

A library for converting HTML to PDF and identifying signature locations. It simplifies document generation, provides support for marking and locating signing areas, and integrates with APIs like Documenso. Designed for use in both local and serverless en

Readme

HTML to PDF and Sign Locations Library

This library provides functionality to convert HTML to PDF and find sign locations within a PDF document. It is designed to work both locally and in serverless environments.

Features

  • Convert HTML strings to PDFs
  • Mark sign locations in HTML
  • Find these areas in generated PDF data
  • Convert sign locations to different coordinate systems
  • Documenso API functionality

Motivation

Even though most business has moved to the digital realm, signing documents by hand or digitally is still an integral part of many areas. However, creating documents with context-specific data can be challenging as PDF editing is notoriously difficult. This can be addressed by generating entire PDF documents from HTML. However, the lack of direct native signature support (Adobe or otherwise) in HTML makes interfacing these documents with digital signature providers difficult.

This library was created to solve this problem by extracting the PDF coordinates of predefined areas in HTML. As many signature services can work with PDF coordinates, this makes interfacing with them significantly easier.

Getting Started

  1. Install the package:
npm i @finum/html-to-pdf-to-sign
  1. Generate a PDF and write it to a file:
import { htmlToPdf } from '@finum/html-to-pdf-to-sign/all.js';

const pdfBuffer = await htmlToPdf({ html: '<h1>Hello, World!</h1>' });
await writeFile(new URL('./example.pdf', import.meta.url), pdfBuffer);
  1. Add signing locations using a special placeholder:
import {
  htmlToPdf,
  getSignLocations,
  SIGN1_BASE64_IMAGE,
} from '@finum/html-to-pdf-to-sign/all.js';

const pdfBuffer = await htmlToPdf({
  html: `
  <h1>Hello, World!</h1>
  <p>Sign Below</p>
  <img
    src="${SIGN1_BASE64_IMAGE}"
    width="200px"
    height="200px"
  />
 `,
});
  1. Get all sign locations and use them to create signatures, for example with Documenso:
import { getSignLocationsDocumenso } from '@finum/html-to-pdf-to-sign/all.js';

const recipients = [{ id: 'foo' }, { id: 'bar' }];

// Example for Documenso
await fetch(`${endpoint}/api/v1/documents/${documentId}/fields`, {
  method: 'POST',
  headers: { Authorization: token, 'Content-Type': 'application/json' },
  body: JSON.stringify(await getSignLocationsDocumenso(pdfBuffer, recipients)),
});
  1. Integrate with your own signature provider:
import { getSignLocations, signLocationsToDocumenso } from '@finum/html-to-pdf-to-sign/all.js';

const signLocations = await getSignLocations(pdfBuffer, {
  targetBasis: 'percent-top-left',
  pageIndexStart: 1,
});
console.log(signLocations);
const recipients = [{ id: 'foo' }, { id: 'bar' }];

// Example Documenso manual
await fetch(`${endpoint}/api/v1/documents/${documentId}/fields`, {
  method: 'POST',
  headers: { Authorization: token, 'Content-Type': 'application/json' },
  body: JSON.stringify(
  signLocations.map(({ x, y, height, width, ref, page }) => ({
    page,
    recipient: recipients[ref],
    pageX: x,
    pageY: y,
    pageHeight: height,
    pageWidth: width
  }))
  ),
});

htmlToPdf.js

This file contains functions to generate a PDF document from HTML.

htmlToPdf(options)

  • Parameters:

    • options (Object): Configuration options for the conversion.
    • html (string): The HTML content to convert. Defaults to 'Please provide your own HTML'.
  • Returns:

    • A Promise that resolves to a Buffer containing the generated PDF.
  • Usage:

    import { htmlToPdf } from '@finum/html-to-pdf-to-sign/all.js';
    
    const pdfBuffer = await htmlToPdf({ html: '<h1>Hello, World!</h1>' });

getSignLocations.js

This file contains functions to find sign locations within a PDF document.

getSignLocations(pdfData, options)

  • Parameters:

    • pdfData (Uint8Array | Buffer): The PDF data.
    • options (Object): Configuration options for finding sign locations.
    • targetBasis (string): The basis for target coordinates. Can be 'pt', 'percent-top-left', or 'percent-bottom-left'. Defaults to 'pt'.
    • pageIndexStart (number): The starting page index. Defaults to 0.
  • Returns:

    • A Promise that resolves to an array of sign locations.
  • Usage:

    import { getSignLocations } from '@finum/html-to-pdf-to-sign/all.js';
    
    const signLocations = await getSignLocations(pdfBuffer, { targetBasis: 'percent-top-left' });

getSignLocationsDocumenso.js

This file contains functions to find sign locations within a PDF document.

getSignLocationsDocumenso(pdfData, recipients)

  • Parameters:

    • pdfData (Uint8Array | Buffer): The PDF data.
    • recipients (Array<{id: string}>): Array containing Documenso recipients. The ordering of recipients corresponds to sign location IDs, e.g., [{id: 'foo'}, {id: 'bar'}] => foo signs SIGN1 locations, bar signs SIGN2 locations. Currently only supports one recipient!
  • Returns:

    • A Promise that resolves to an array of Documenso sign locations.
  • Usage:

    import { getSignLocationsDocumenso } from '@finum/html-to-pdf-to-sign/all.js';
    
    const signLocations = await getSignLocationsDocumenso(pdfBuffer, [{ id: 'foo' }, { id: 'bar' }]);

Having Issues?

Open an issue on GitHub