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

api2pdf

v2.0.3

Published

This client library is a wrapper for the Api2Pdf.com REST API. See full REST api documentation at https://www.api2pdf.com/documentation/v2. Api2Pdf is a powerful API that supports HTML to PDF, URL to PDF, HTML to Image, URL to Image, Thumbnail / image pre

Downloads

5,993

Readme

api2pdf.node

Nodejs client for Api2Pdf REST API

Api2Pdf.com is a powerful REST API for instantly generating PDF and Office documents from HTML, URLs, Microsoft Office Documents (Word, Excel, PPT), Email files, and images. You can generate image preview or thumbnail of a PDF, office document, or email file. The API also supports merge / concatenation of two or more PDFs, setting passwords on PDFs, and adding bookmarks to PDFs. Api2Pdf is a wrapper for popular libraries such as wkhtmltopdf, Headless Chrome, PdfSharp, and LibreOffice.

Installation

npm install --save api2pdf

Resources

Resources this API supports:

Authorization

Acquire API Key

Create an account at portal.api2pdf.com to get your API key.

Usage

Initialize the Client

All usage starts by requiring api2pdf and creating a new object.

var Api2Pdf = require('api2pdf');   
var a2pClient = new Api2Pdf('YOUR-API-KEY');

Once you initialize the client, you can make calls like so:

a2pClient.chromeUrlToPdf('https://www.github.com')
    .then(function(result) {
        console.log(result); //successful api call
    }, function(rejected) {
        console.log(rejected); //an error occurred
    }
);

Successful Result Format

{
    'FileUrl': 'https://link-to-file-only-available-for-24-hours',
    'MbOut': 0.08830547332763672,
    'Cost': 0.00017251586914062501,
    'Success': true,
    'Error': null,
    'ResponseId': '6e46637a-650d-46d5-af0b-3d7831baccbb'
}

Failed Result Format

{
    'Success': false,
    'Error': 'some reason for the error',
    'ResponseId': '6e46637a-650d-46d5-af0b-3d7831baccbb'
}

wkhtmltopdf

Convert HTML to PDF

a2pClient.wkHtmlToPdf('<p>Hello, World</p>').then(function(result) {
    console.log(result);
});

Convert HTML to PDF (download PDF as a file and specify a file name)

a2pClient.wkHtmlToPdf('<p>Hello, World</p>', { inline: false, filename: 'test.pdf' }).then(function(result) {
    console.log(result);
});

Convert HTML to PDF (use object for advanced wkhtmltopdf settings) View full list of wkhtmltopdf options available.

var options = { orientation: 'landscape', pageSize: 'A4'};
a2pClient.wkHtmlToPdf('<p>Hello, World</p>', { options: options }).then(function(result) {
    console.log(result);
});

Convert URL to PDF

a2pClient.wkUrlToPdf('https://www.github.com').then(function(result) {
    console.log(result);
});

Convert URL to PDF (download PDF as a file and specify a file name)

a2pClient.wkUrlToPdf('https://www.github.com', { inline: false, filename: 'test.pdf' }).then(function(result) {
    console.log(result);
});

Convert URL to PDF (use object for advanced wkhtmltopdf settings) View full list of wkhtmltopdf options available.

var options = { orientation: 'landscape', pageSize: 'A4'};
a2pClient.wkUrlToPdf('https://www.github.com', { options: options }).then(function(result) {
    console.log(result);
});

Headless Chrome

Convert HTML to PDF

a2pClient.chromeHtmlToPdf('<p>Hello, World</p>').then(function(result) {
    console.log(result);
});

Convert HTML to PDF (download PDF as a file and specify a file name)

a2pClient.chromeHtmlToPdf('<p>Hello, World</p>', { inline: false, filename: 'test.pdf' }).then(function(result) {
    console.log(result);
});

Convert HTML to PDF (use options for advanced Headless Chrome settings) View full list of Headless Chrome options available.

var options = { landscape: true };
a2pClient.chromeHtmlToPdf('<p>Hello, World</p>', { options: options }).then(function(result) {
    console.log(result);
});

Convert URL to PDF

a2pClient.chromeUrlToPdf('https://www.github.com').then(function(result) {
    console.log(result);
});

Convert URL to PDF (download PDF as a file and specify a file name)

a2pClient.chromeUrlToPdf('https://www.github.com', { inline: false, filename: 'test.pdf' }).then(function(result) {
    console.log(result);
});

Convert URL to PDF (use keyword arguments for advanced Headless Chrome settings) View full list of Headless Chrome options available.

var options = { landscape: true };
a2pClient.chromeUrlToPdf('https://www.github.com', { options: options }).then(function(result) {
    console.log(result);
});

Convert HTML to Image

a2pClient.chromeHtmlToImage('<p>Hello, World</p>').then(function(result) {
    console.log(result);
});

Convert URL to Image

a2pClient.chromeUrlToImage('https://www.github.com').then(function(result) {
    console.log(result);
});

LibreOffice

Convert any office file to PDF, image file to PDF, email file to PDF, HTML to Word, HTML to Excel, and PDF to HTML. Any file that can be reasonably opened by LibreOffice should be convertible. Additionally, we have an endpoint for generating a thumbnail of the first page of your PDF or Office Document. This is great for generating an image preview of your files to users.

You must provide a url to the file. Our engine will consume the file at that URL and convert it.

Convert Microsoft Office Document or Image to PDF

a2pClient.libreOfficeAnyToPdf('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx').then(function(result) {
    console.log(result);
});

Convert Microsoft Office Document or Image to PDF (download PDF as a file and specify a file name)

a2pClient.libreOfficeAnyToPdf('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx', { inline: false, filename: 'test.pdf' }).then(function(result) {
    console.log(result);
});

Thumbnail or Image Preview of a PDF or Office Document or Email file

a2pClient.libreOfficeThumbnail('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx').then(function(result) {
    console.log(result);
});

Convert HTML to Microsoft Word or Docx

a2pClient.libreOfficeHtmlToDocx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html').then(function(result) {
    console.log(result);
});

Convert HTML to Microsoft Excel or Xlsx

a2pClient.libreOfficeHtmlToXlsx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html').then(function(result) {
    console.log(result);
});

Convert PDF to HTML

a2pClient.libreOfficePdfToHtml('http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf').then(function(result) {
    console.log(result);
});

PdfSharp - Merge / Concatenate Two or More PDFs, Add bookmarks to pdfs, add passwords to pdfs

To use the merge endpoint, supply a list of urls to existing PDFs. The engine will consume all of the PDFs and merge them into a single PDF, in the order in which they were provided in the list.

Merge PDFs from list of URLs to existing PDFs

var urls = ['url-to-pdf1', 'url-to-pdf2'];
a2pClient.pdfsharpMerge(urls).then(function(result) {
    console.log(result);
});

Add bookmarks to existing PDF

var url = 'https://LINK-TO-PDF';
var bookmarks = [
    { Page: 0, Title: "Introduction"},
    { Page: 1, Title: "Second page"}
]
a2pClient.pdfsharpAddBookmarks(url, bookmarks).then(function(result) {
    console.log(result);
});

Add password to existing PDF

var url = 'https://LINK-TO-PDF';
var userpassword = "hello";
a2pClient.pdfsharpAddPassword(url, userpassword).then(function(result) {
    console.log(result);
});

Compress existing PDF

var url = 'https://LINK-TO-PDF';
a2pClient.pdfsharpCompress(url).then(function(result) {
    console.log(result);
});

Extract pages from existing PDF

var url = 'https://LINK-TO-PDF';
var start = "2";
var end = null;
a2pClient.pdfsharpExtractPages(url, start, end).then(function(result) {
    console.log(result);
});

Helper Methods

Delete a PDF on Command with delete(responseId)

By default, Api2Pdf will delete your generated file 24 hours after it has been generated. For those with high security needs, you may want to delete your file on command. You can do so by making an DELETE api call with the responseId attribute that was returned on the original JSON payload.

var responseId = result.ResponseId //from previous api call
a2pClient.utilityDelete(responseId);