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

docstron

v1.0.3

Published

Node.js SDK for Docstron PDF Generation API - Complete Features

Readme

Docstron SDK for Node.js

npm version License: MIT

The official Node.js library for the Docstron PDF Generation API.

📋 What's Included

Template Management

  • Create templates with HTML content
  • Get template details
  • Update existing templates
  • Delete templates
  • List all templates

Installation

npm install docstron

Configuration

Add your API key to your environment:

DOCSTRON_API_KEY=your-api-key
DOCSTRON_BASE_URL=https://api.docstron.com/v1

Quick Start

const Docstron = require("docstron");

// Initialize the client
const client = new Docstron();

// Create a template
const template = await client.templates.create({
  application_id: "app-xxx",
  name: "Invoice Template",
  content: "<h1>Invoice #{{invoice_number}}</h1><p>Total: {{total}}</p>",
  is_active: true,
});

console.log("Template created:", template.template_id);

Authentication

Get your API key from your Docstron Dashboard.

const client = new Docstron();

// With custom options
const client = new Docstron("your-api-key-here", {
  baseURL: "https://api.docstron.com/v1",
});

API Reference

Templates

templates.create(params)

Create a new PDF template.

Parameters:

  • application_id (string, required) - Your application ID
  • name (string, required) - Template name
  • content (string, required) - HTML content with {{placeholders}}
  • is_active (boolean, optional) - Active status (default: true)
  • extra_css (string, optional) - Additional CSS rules for PDF styling

Returns: Promise

Example:

const template = await client.templates.create({
  application_id: "app-7b4d78fb-820c-4ca9-84cc-46953f211234",
  name: "Invoice Template",
  content: `
    <html>
      <body>
        <h1>Invoice</h1>
        <p>Customer: {{customer_name}}</p>
        <p>Total: {{total_amount}}</p>
      </body>
    </html>
  `,
  is_active: true,
  extra_css: "@page { margin: 2cm; }",
});

templates.get(templateId)

Retrieve a specific template by ID.

Parameters:

  • templateId (string, required) - The template ID

Returns: Promise

Example:

const template = await client.templates.get("template-xxx");
console.log(template.name);

templates.update(templateId, params)

Update an existing template.

Parameters:

  • templateId (string, required) - The template ID
  • params (object, required) - Fields to update

Returns: Promise

Example:

const updated = await client.templates.update("template-xxx", {
  name: "Updated Invoice Template",
  is_active: false,
});

templates.delete(templateId)

Delete a template.

Parameters:

  • templateId (string, required) - The template ID

Returns: Promise

Example:

await client.templates.delete("template-xxx");
console.log("Template deleted");

templates.list(applicationId)

List all templates for an application.

Parameters:

  • applicationId (string, required) - The application ID

Returns: Promise

Example:

const templates = await client.templates.list("app-xxx");
console.log(`Found ${templates.length} templates`);

Documents (v0.2.0+)

documents.generate(templateId, options)

Generate a PDF from a template.

Parameters:

  • templateId (string, required) - Template ID
  • options.data (object, required) - Data for placeholders
  • options.response_type (string, optional) - 'pdf', 'json_with_base64', or 'document_id' (default)
  • options.password (string, optional) - Password protect the PDF

Returns: Document object or PDF buffer

Example:

const doc = await client.documents.generate(templateId, {
  data: {
    customer_name: "John Doe",
    invoice_number: "INV-001",
    total: "$299.00",
  },
  response_type: "document_id",
});

console.log("Download URL:", doc.download_url);

documents.quickGenerate(options)

Generate a PDF without creating a template first.

Parameters:

  • options.html (string, required) - HTML content
  • options.data (object, required) - Data for placeholders
  • options.response_type (string, optional) - Response format
  • options.extra_css (string, optional) - Additional CSS
  • options.save_template (boolean, optional) - Save as reusable template
  • options.application_id (string, conditional) - Required if save_template is true
  • options.password (string, optional) - Password protect the PDF

Example:

const doc = await client.documents.quickGenerate({
  html: "<h1>Hello {{name}}</h1>",
  data: { name: "World" },
  response_type: "document_id",
});

documents.get(documentId)

Get document details.

Example:

const doc = await client.documents.get("document-xxx");
console.log(doc.template_id, doc.created_at);

documents.list()

List all documents.

Example:

const docs = await client.documents.list();
console.log(`Total documents: ${docs.length}`);

documents.download(documentId, filepath)

Download a PDF document.

Parameters:

  • documentId (string, required) - Document ID
  • filepath (string, optional) - Local path to save the PDF

Example:

// Save to file
await client.documents.download("document-xxx", "./invoice.pdf");

// Get as buffer
const buffer = await client.documents.download("document-xxx");

documents.update(documentId, data)

Update document data.

documents.delete(documentId)

Delete a document.

Applications

applications.create(params)

Create a new application to organize your templates and documents.

Parameters:

  • params.name (string, required) - Application name
  • params.description (string, optional) - Application description
  • params.is_active (boolean, optional) - Active status (default: true)

Returns: Promise

Example:

const app = await client.applications.create({
  name: "Invoice System",
  description: "Manages all customer invoices",
  is_active: true,
});

console.log("App ID:", app.app_id);

applications.get(appId)

Get details of a specific application.

Example:

const app = await client.applications.get("app-xxx");
console.log(app.name, app.is_active);

applications.list()

List all applications in your account.

Example:

const apps = await client.applications.list();
console.log(`Total applications: ${apps.length}`);

apps.forEach((app) => {
  console.log(`- ${app.name} (${app.is_active ? "Active" : "Inactive"})`);
});

applications.update(appId, params)

Update an existing application.

Parameters:

  • appId (string, required) - Application ID
  • params.name (string, optional) - New name
  • params.description (string, optional) - New description
  • params.is_active (boolean, optional) - New active status

Example:

const updated = await client.applications.update("app-xxx", {
  name: "Updated Invoice System",
  is_active: false,
});

applications.delete(appId)

Delete an application.

Example:

await client.applications.delete("app-xxx");
console.log("Application deleted");

Response Types

When generating documents, you can choose the response format:

document_id (default)

Returns document ID and download URL - best for most use cases.

{
  document_id: "document-xxx",
  template_id: "template-xxx",
  download_url: "https://api.docstron.com/v1/documents/download/document-xxx",
  size_bytes: 5370
}

json_with_base64

Returns base64-encoded PDF content - useful for immediate processing.

{
  document_id: "document-xxx",
  pdf_content: "JVBERi0xLjcK...",
  filename: "document.pdf",
  size_bytes: 5370
}

pdf

Returns raw PDF binary data - useful for direct download endpoints.

Template Placeholders

Use double curly braces to create dynamic placeholders:

<h1>Hello {{customer_name}}!</h1>
<p>Order #{{order_number}} - Total: {{total_amount}}</p>
<p>Date: {{order_date}}</p>

When generating PDFs, you'll pass data to fill these placeholders:

{
  customer_name: "John Doe",
  order_number: "12345",
  total_amount: "$299.00",
  order_date: "2025-11-08"
}

Error Handling

The SDK provides specific error types for better error handling:

const {
  DocstronError,
  ValidationError,
  AuthenticationError,
  NotFoundError
} = require('docstron');

try {
  await client.templates.create({...});
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Validation failed:');
    error.errors.forEach(err => {
      console.error(`- ${err.field}: ${err.message}`);
    });
  } else if (error instanceof AuthenticationError) {
    console.error('Invalid API key');
  } else if (error instanceof NotFoundError) {
    console.error('Template or application not found');
  } else if (error instanceof DocstronError) {
    console.error('API error:', error.message);
  } else {
    console.error('Unexpected error:', error);
  }
}

Requirements

  • Node.js >= 14.0.0
  • A Docstron account and API key

Support

  • 📧 Email: [email protected]
  • 📚 Documentation: https://docs.docstron.com
  • 🐛 Issues: https://github.com/playiiit/docstron-nodejs-sdk/issues
  • 💬 Discussions: https://github.com/playiiit/docstron-nodejs-sdk/discussions

Contributors

Contributing

Contributions are welcome! This is an early-stage project, and we'd love your help making it better.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request