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 🙏

© 2024 – Pkg Stats / Ryan Hefner

doppio-nodejs

v0.9.0

Published

The doppio.sh official library - HTML to PDF - HTML to Screenshot - Templates

Downloads

97

Readme

Official Doppio.sh Node.js SDK

The Doppio.sh SDK enables developers to easily integrate HTML to PDF, HTML to Screenshot, Template to PDF and Template to Screenshot rendering functionalities into their Node.js applications.

This SDK provides straightforward methods for interacting with the Doppio.sh API, supporting both ECMAScript Modules (ESM) and CommonJS (CJS) formats, ensuring compatibility with various Node.js environments.

Below are examples to get you started. For additional examples, please see our official documentation at https://doc.doppio.sh.

Key Features:

  • Generate PDFs and Screenshots from HTML/CSS/JS.
  • Render custom templates.
  • Asynchronous and synchronous API calls.
  • Lightweight with zero dependencies.

Install

  • Requires node.js >=17.5
npm install doppio-nodejs

Once installed, you can import the library using import or require :

const { Doppio } = require('doppio-nodejs');
// OR
import { Doppio } from 'doppio-nodejs';

Exemple

Renders a PDF and writes a file on disk

import fs from 'fs/promises';
import { Doppio } from 'doppio-nodejs';

const doppioClient = new Doppio(process.env.DOPPIO_API_KEY);

const buffer = await doppioClient.renderPdfDirect({
  pdf: {
    printBackground: true,
  },
  setContent: {
    html: 'PGh0bWw+CjxwPnRlc3Q8L3A+CjwvaHRtbD4=',
    options: {
      waitUntil: ['networkidle0'],
    },
  },
});

await fs.writeFile('./tmp/pdf-output.pdf', Buffer.from(buffer));

Renders a PDF Async, with a webhook

import { Doppio } from 'doppio-nodejs';
const doppioClient = new Doppio(process.env.DOPPIO_API_KEY);

doppioClient.doppio({
  webhook: {
    url: 'https://webhook.site/your-webhook-url',
    method: 'POST',
  },
});

const response = await doppioClient.renderPdfAsync({
  pdf: {
    printBackground: true,
  },
  setContent: {
    html: 'PGh0bWw+CjxwPnRlc3Q8L3A+CjwvaHRtbD4=',
    options: {
      waitUntil: ['networkidle0'],
    },
  },
});

Functions

// Sets the Doppio config, similiar to the doppio object in the API
doppio(doppioConfigObject: DoppioConfig | DoppioAsyncConfig): void;

// Sets launch config, similiar to the launch object in the API
launch(launchConfigObject: LaunchConfig): void;

// Renders a PDF, outputs the file as a Buffer
renderPdfDirect(PagePdfConfigObject: PagePdfConfig): Promise<ArrayBuffer>;

// Renders a Screenshot, outputs the file as a Buffer
renderScreenshotDirect(PageScreenshotConfigObject: PageScreenshotConfig): Promise<ArrayBuffer>;

// Renders a PDF, outputs an object with a documentUrl property
renderPdfSync(PagePdfConfigObject: PagePdfConfig): Promise<DoppioResponse>;

// Renders a Screenshot, outputs an object with a documentUrl property
renderScreenshotSync(PageScreenshotConfigObject: PageScreenshotConfig): Promise<DoppioResponse>;

// Starts an async render for a PDF, outputs an object with a requestId property
renderPdfAsync(PagePdfConfigObject: PagePdfConfig): Promise<DoppioResponseAsync>;

// Starts an async render for a Screenshot, outputs an object with a requestId property
renderScreenshotAsync(PageScreenshotConfigObject: PageScreenshotConfig): Promise<DoppioResponseAsync>;

// Renders a template, outputs the file as a Buffer
renderTemplateDirect(TemplateConfigObject: TemplateConfig): Promise<ArrayBuffer>;

// Renders a template, outputs an object with a documentUrl property
renderTemplateSync(TemplateConfigObject: TemplateConfig): Promise<DoppioResponse>;

// Starts an async render for a template, outputs an object with a requestId property
renderTemplateAsync(TemplateConfigObject: TemplateConfig): Promise<DoppioResponseAsync>;

Getting Help

For more detailed examples and API documentation, please visit our official documentation. If you encounter any issues or have questions, feel free to open an issue on GitHub, send an email and reach out on chat.

Contributing

Contributions to the Doppio.sh SDK are welcome!