JavaScript Library

ConvertAPI JavaScript Client

Convert your files with our online file conversion API

The ConvertAPI helps converting various file formats. Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages. Merge, Encrypt, Split, Repair and Decrypt PDF files. And many others files manipulations. In just few minutes you can integrate it into your application and use it easily.

The ConvertAPI-JS library makes it easier to use the Convert API from your web projects without having to build your own API calls. You can get your free API secret at https://www.convertapi.com/a

If you are interested in our old version of non-module JavaScript library you can find it here.

Try it online

You can try this library on CodeSandbox

Installation

Run this line from console:

npm i convertapi-js@~1.1

Usage

Configuration

You can get your secret at https://www.convertapi.com/a

import ConvertApi from 'convertapi-js'
let convertApi = ConvertApi.auth('<YOUR_SECRET>')

File conversion

Example to convert DOCX file to PDF. All supported formats and options can be found here.

let params = convertApi.createParams()
params.add('file', elFileInput.files[0])
let result = await convertApi.convert('docx', 'pdf', params)

// Get result file URL
let url = result.files[0].Url

Convert remote file

let params = convertApi.createParams()
params.add('file', new URL('https://cdn.convertapi.com/test-files/presentation.pptx'))
let result = await convertApi.convert('pptx', 'pdf', params)

// Get result file URL
let url = result.files[0].Url

Additional conversion parameters

ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion parameters and explanations can be found here.

// Converting PDF to JPG file
let params = convertApi.createParams()
params.add('file', e.currentTarget.files[0])
params.add('ScaleImage', 'true')
params.add('ScaleProportions', 'true')
params.add('ImageHeight', '300')
params.add('ImageWidth', '300')
let result = await convertApi.convert('pdf', 'jpg', params)

// Get result file URL
let url = result.files[0].Url

Issues & Comments

Please leave all comments, bugs, requests, and issues on the Issues page. We'll respond to your request ASAP!

License

The ConvertAPI JS Library is licensed under the MIT license. Refere to the LICENSE file for more information.