Skip to content
A node library for interacting with pdf.kiwi API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.babelrc
.editorconfig
.eslintrc.json
.gitignore
.npmignore
.nycrc
.travis.yml
CHANGELOG.md
LICENSE.md
README.md
index.js
package.json
yarn.lock

README.md

pdfkiwi-node

A node library for interacting with pdf.kiwi API

Build Status Coverage Status

Installation

# - Npm
npm install pdfkiwi --save

# - Yarn
yarn add pdfkiwi

Usage

Start by instantiating a client instance:

const pdf = require('pdfkiwi');

const client = new pdf.Pdfkiwi('[api email]', ['api token']);

You can then use any of the methods described below.

  • Available options (for the options parameters) are listed on this page.
  • API error codes are listed on this page.
  • All of these methods return a promise.
  • The promise is resolved with a Buffer containing the PDF binary data,
    You can use built-in utility functions to save or download the pdf directly.
    (see Built-in utility functions)

.convertHtml() - Convert HTML string to PDF

Pdfkiwi.convertHtml(html: String|Number, options: Object): Promise

Exemple:

client.convertHtml('<h1>Hello world</h1>', { orientation: 'landscape' })
    .then(pdf.saveToFile('./my-pdf-file.pdf'))
    .then(() => { console.log('done !'); })
    .catch((err) => {
        // err.code   : Api error code (if available)
        // err.status : Http code (if available)
        console.log(err);
    });

Built-in utility functions

pdf.saveToFile() — Saves the generated PDF to a file.

pdf.saveToFile(filePath: String): Function
  • If the filePath has no extension, the .pdf extension will be automatically appended.
  • The filePath path is resolved regarding the current working directory.

Exemple:

client.convertHtml('<h1>Hello world</h1>')
    .then(pdf.saveToFile('/path/to/my-file.pdf'))
    .catch((err) => { console.log(err); });

pdf.sendHttpResponse() — Returns the generated PDF in an HTTP response.

pdf.sendHttpResponse(response: http.ServerResponse, fileName: String): Function
  • If the fileName has no extension, the .pdf extension will be automatically appended.

Exemple:

const express = require('express');
const app = express();

app.get('/pdf', (request, response) => {
    client.convertHtml('<h1>Hello world</h1>')
        .then(pdf.sendHttpResponse(response, 'my-file'))
        .catch((err) => { console.log(err); });
});

app.listen(3000);

Useful links

You can’t perform that action at this time.