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

@contract-js/core

v1.1.4

Published

[//]: # (@contract-js/core - PDF Contract Generation)

Readme

📄 @contract-js/core

PDF Contract Generation from EJS Templates

Generate PDF contracts from EJS templates with digital signature support and comprehensive metadata management.

npm version License: Apache-2.0 TypeScript


🎯 Purpose

Generate professional PDF contracts from EJS templates with support for dynamic data, comprehensive metadata management, and digital signature integration.

✨ Features

  • PDF Generation – Convert EJS templates to PDF documents using Puppeteer
  • Template Rendering – Render EJS templates with dynamic data
  • Metadata Management – Set and extract PDF metadata (title, author, creator, producer, etc.)
  • Template Loading – Load EJS templates from file system
  • Browser Configuration – Customize Puppeteer browser options for different environments
  • Digital Signature Ready – Generate PDFs compatible with digital signatures
  • TypeScript Support – Full TypeScript support with comprehensive type definitions

🚀 Usage

Basic PDF Generation

import { generatePdf } from '@contract-js/core';

const result = await generatePdf({
  templateContent: '<h1>Hello <%= name %>!</h1>',
  templateData: {
    name: 'John Doe'
  },
  pdfConfig: {
    metadata: {
      title: 'Sample Contract',
      author: 'ABC Corp',
      creator: 'Contract-JS',
      producer: 'Contract-JS PDF Engine'
    }
  },
  browserOptions: {
    disableDevShmUsage: true,
    disableGpu: true
  }
});

console.log(`PDF generated: ${result.pdfKB}KB`);
console.log(`Hash: ${result.pdfHash}`);

Template Loading and Rendering

import { loadTemplate, generatePdf } from '@contract-js/core';

// Load template from file
const templateContent = await loadTemplate({
  templatePath: './template.ejs'
});

// Generate PDF with loaded template
const result = await generatePdf({
  templateContent,
  templateData: {
    title: 'Service Agreement',
    clientName: 'John Doe',
    date: '2024-01-15'
  },
  pdfConfig: {
    options: {
      format: 'A4',
      margin: {
        top: '20mm',
        bottom: '20mm',
        left: '15mm',
        right: '15mm'
      }
    },
    metadata: {
      title: 'Service Agreement',
      author: 'ABC Corp',
      creator: 'Contract-JS Generator',
      producer: 'Contract-JS PDF Engine',
      keywords: ['contract', 'agreement', 'service']
    }
  }
});

PDF Metadata Extraction

import { getPdfMetadata } from '@contract-js/core';
import { readFile } from 'node:fs/promises';

const pdfBuffer = await readFile('contract.pdf');
const metadata = await getPdfMetadata(pdfBuffer);

console.log('PDF Metadata:', {
  title: metadata.title,
  author: metadata.author,
  creator: metadata.creator,
  producer: metadata.producer,
  createDate: metadata.createDate,
  modDate: metadata.modDate
});

📦 Installation

# npm
npm install @contract-js/core

# pnpm (recommended)
pnpm add @contract-js/core

# yarn
yarn add @contract-js/core

📋 API Reference

Core Functions

| Function | Description | Parameters | Returns | |----------|-------------|------------|---------| | generatePdf | Generate PDF from EJS template | templateContent, templateData, templateOptions?, pdfConfig?, browserOptions? | Promise<PDFResult> | | loadTemplate | Load EJS template from file | templatePath, templateReadOptions? | Promise<string> | | getPdfMetadata | Extract metadata from PDF | pdfBuffer | Promise<PDFMetadata> |

Types

PDFResult

type PDFResult = {
  pdfBuffer: Buffer;
  pdfHash: string;
  pdfKB: number;
};

PDFMetadata

type PDFMetadata = {
  title?: string;
  author?: string;
  subject?: string;
  keywords?: string[];
  producer?: string;
  creator?: string;
  createDate?: Date;
  modDate?: Date;
};

TemplateData

type TemplateData = {
  [key: string]: string | number | TemplateData;
};

BrowserOptions

type BrowserOptions = {
  executablePath?: string;
  disableDevShmUsage?: boolean;
  disableGpu?: boolean;
  singleProcess?: boolean;
};

PDF Configuration Options

The pdfConfig parameter accepts:

{
  options?: PDFOptions; // Puppeteer PDF options
  metadata?: PDFMetadata; // PDF metadata
}

Browser Configuration Options

The browserOptions parameter allows customization of Puppeteer browser settings:

{
  executablePath?: string; // Custom Chrome/Chromium executable path
  disableDevShmUsage?: boolean; // Disable /dev/shm usage (useful in Docker)
  disableGpu?: boolean; // Disable GPU acceleration
  singleProcess?: boolean; // Run in single process mode
}

Default PDF Options

  • Format: A4
  • Print Background: true
  • Margins: 20mm top/bottom, 15mm left/right

Default Metadata

  • Creator: Contract-JS Generator
  • Producer: Contract-JS PDF Engine
  • Create Date: Current date

🔧 Advanced Usage

Custom PDF Options

const result = await generatePdf({
  templateContent,
  templateData,
  pdfConfig: {
    options: {
      format: 'Letter',
      printBackground: true,
      margin: {
        top: '1in',
        bottom: '1in',
        left: '0.5in',
        right: '0.5in'
      },
      displayHeaderFooter: true,
      headerTemplate: '<div>Header</div>',
      footerTemplate: '<div>Footer</div>'
    }
  }
});

Template Options

const result = await generatePdf({
  templateContent,
  templateData,
  templateOptions: {
    delimiter: '%',
    openDelimiter: '<%',
    closeDelimiter: '%>',
    strict: false
  }
});

Browser Options (Docker/Server Environments)

const result = await generatePdf({
  templateContent,
  templateData,
  browserOptions: {
    disableDevShmUsage: true, // Recommended for Docker
    disableGpu: true, // Recommended for headless servers
    singleProcess: true // For memory-constrained environments
  }
});

🛠️ Dependencies

  • pdf-lib: PDF manipulation and metadata management
  • puppeteer: HTML to PDF conversion
  • ejs: Template engine
  • @contract-js/pdf-utils: PDF utilities (hash generation)

📝 License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © Jeonhui