Image to Image in Node.js

This page describes how to use our cloud-based API to convert between images formats in Node.js. The API is user-friendly and can be integrated into your application with just a few lines of code.

Installation

The Node.js API client library provides easy access to the Pdfcrowd API. No third-party libraries are required.

Install the client library from npm
npm install pdfcrowd

We also offer other installation options.

Authentication

The credentials to access the API are your Pdfcrowd username and the API key.

API Method Reference

Refer to the Image to Image Node.js Reference for a description of all API methods.

Code Examples

Here are a few Node.js examples to get you started quickly with the API. See more examples.

var pdfcrowd = require("pdfcrowd");

// create the API client instance
var client = new pdfcrowd.ImageToImageClient("your_username", "your_apikey");

// configure the conversion
try {
    client.setOutputFormat("jpg");
} catch(why) {
    // report the error
    console.error("Pdfcrowd Error: " + why);
    process.exit(1);
}

// run the conversion and write the result to a file
client.convertFileToFile(
    "/path/to/logo.png",
    "logo.jpg",
    function(err, fileName) {
        if (err) return console.error("Pdfcrowd Error: " + err);
        console.log("Success: the file was created " + fileName);
    });
var pdfcrowd = require("pdfcrowd");

// create the API client instance
var client = new pdfcrowd.ImageToImageClient("your_username", "your_apikey");

// configure the conversion
try {
    client.setOutputFormat("jpg");
} catch(why) {
    // report the error
    console.error("Pdfcrowd Error: " + why);
    process.exit(1);
}

// run the conversion and write the result to a file
client.convertUrlToFile(
    "https://pdfcrowd.com/static/images/logo.png",
    "logo.jpg",
    function(err, fileName) {
        if (err) return console.error("Pdfcrowd Error: " + err);
        console.log("Success: the file was created " + fileName);
    });
var pdfcrowd = require("pdfcrowd");
var fs = require("fs");

// create the API client instance
var client = new pdfcrowd.ImageToImageClient("your_username", "your_apikey");

// configure the conversion
try {
    client.setOutputFormat("jpg");
} catch(why) {
    // report the error
    console.error("Pdfcrowd Error: " + why);
    process.exit(1);
}

// run the conversion and write the result to a file
client.convertRawDataToFile(
    fs.readFileSync("/path/to/logo.png"),
    "logo.jpg",
    function(err, fileName) {
        if (err) return console.error("Pdfcrowd Error: " + err);
        console.log("Success: the file was created " + fileName);
    });

Troubleshooting