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

pdf4dev-node-client

v1.0.3

Published

PDF4.dev - Node Client

Downloads

6

Readme

PDF4.dev - Node Client

This is the officially supported node.js library for using our PDF4.dev API

You can sign up for a PDF4.dev account at https://pdf4.dev. Register now and receive 50 credits for free. ❤️

✨ Features

Create PDF:

  • Create from HTML Code.
  • Create from Website URL.
  • Create from Documents (doc, docx, ppt, pptx, xml, xmlx and odt, ods, odp).
  • Create from Images.
  • Create or add elements to a PDF using a JSON.

PDF Utilities:

  • Merge multiples files in one file.
  • Reorganize (Remove or change pages order, split in multiple files, etc).
  • Protect - Unprotect.
  • Fill and List fields.
  • Repair.

Create Images:

  • Create from HTML Code.
  • Create from Website URL (Screenshot).
  • Create from a PDF file.

QR - Barcodes:

  • Read QR - Barcodes from a PDF or an Image file.
  • Create QR - Barcodes.

Create Documents:

  • Create from a PDF file (doc, docx).

🚀 Quickstart

1. Installing the client library

npm install --save pdf4dev-node-client

2. Setting the API Key

2.1 Get an API Key:

  • Login into the dashboard panel.
  • Navigate to API Keys.
  • Press Create new API Key and follow the steps.

2.2 Configuration:

const { PDF4dev } = require("pdf4dev-node-client");

const pdf4dev = new PDF4dev({
  apiKey: "your-api-key",
});

💡 You can also set your API key using the PDF4DEV_API_KEY environment variable. It'll look better!

3. Make your first operation

const html = "<h1>Hello World</h1>";

// HTML to PDF
const operation = await pdf4dev.htmlToPdf(html);

// Save to a file
await operation.save("result.pdf");

Also you can make something like this:

pdf4dev.htmlToPdf(html).then((operation) => {
  operation.save("result.pdf").then(() => {
    console.log("Success");
  });
});

🎉 That's all! You can check for more below or [here](https://github.com/pdf4dev/pdf4dev-node-client/tree/main/examples.

📥 Downloading the files

When you have an operation you'll be able to:

// Download and save the file:
await operation.save("result.pdf");

// Or get a buffer:
const buffer = await operation.download();

Sometimes you'll get more than one file (For example, when you convert a PDF with multiple pages to images). In those cases you can:

// Download and save files in a folder:
await operation.saveAll("/my-folder");

// Or get an array of buffers:
const buffer = await operation.downloadAll();

📤 Uploading your local files

We use our Storage API to upload your local files to the server. It works transparent, for example:

// The file is on internet, so we'll use the specified URL directly:
await pdf4dev.barcodeReader("https://your-address.com/remote-file.pdf");

// The file is local, we'll upload it:
await pdf4dev.barcodeReader("./local-file.pdf");

// If you want you can use a buffer, we'll upload it too:
const buffer = fs.readFileSync("./local-file.pdf");
await pdf4dev.barcodeReader(buffer);

✨ Examples

💡 You can find these examples and more within the project right here.

HTML to PDF

const html = "<h1>Hello {{name}}</h1>";

const operation = await pdf4dev.htmlToPdf(html, {
  template: {
    name: "World",
  },
});

await operation.save("./output/html-to-pdf.pdf");

WEB to PDF

const url = "https://www.wikipedia.org/";
const operation = await pdf4dev.webToPdf(url);

await operation.save("./output/web-to-pdf.pdf");

Document to PDF

const file = fs.readFileSync("./files/document.docx");
const operation = await pdf4dev.documentToPdf(file);

await operation.save("./output/document-to-pdf.pdf");

Read QR - Barcodes

const file = fs.readFileSync("./files/barcodes.pdf");
const operation = await pdf4dev.barcodeReader(file);

for (let code of operation.output.barcodes) {
  console.log(code.value);
}

WEB To Image (Screenshot)

const url = "https://en.wikipedia.org/wiki/Madrid";

const operation = await pdf4dev.webToImage(url, {
  output: IMAGE_FORMAT.PNG,
  options: {
    fullPage: true,
  },
});

💡 Check out for more examples here.

💣 Advanced options

Asynchronous operations

It's possible to use this library to make asynchronous operations.

You can specified the callback URL when you create the instance:

const pdf4dev = new PDF4dev({
  callbackUrl: "https://url-to-your-server/",
});

Keep in mind that you won't be able to download the generated files:

const operation = await pdf4dev.htmlToPdf("<h1>Hello World</h1>");

// Oops! You'll get an error:
await operation.save("result.pdf");

However, If you want you can use this library to handle the received request from our API:

const { Operation } = require("pdf4dev-client");

const handler = async (req, res, next) => {
  const operation = new Operation(req.body);
  await operation.save("result.pdf");
};