Skip to main content
GuideNode.js

How to Use the PDF to Word API in Node.js

Step-by-step guide to convert PDF files to Word documents (DOCX) using the Convert Fleet REST API in Node.js. Includes full code example with axios and form-data.

LanguageNode.js
Conversionpdfdocx
API ReferenceView Endpoint →

You need an API key to follow this guide. Get a free API key →

1Install Dependencies

Install the required npm packages: axios for HTTP requests and form-data for multipart file uploads.

bash
npm install axios form-data

2Get Your API Key

Sign up at convertfleet.com, go to your dashboard, and generate a free API key. Keep it secure — never expose it in client-side code.

3Write the Conversion Code

Use the following Node.js code to send a PDF file and receive a Word document in response.

javascript
const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');

async function convertPdfToWord(inputPath, outputPath) {
  const form = new FormData();
  form.append('file', fs.createReadStream(inputPath));
  form.append('to', 'docx');

  const response = await axios.post(
    'https://convertfleet.com/api/convert',
    form,
    {
      headers: {
        ...form.getHeaders(),
        'Authorization': 'Bearer YOUR_API_KEY',
      },
      responseType: 'arraybuffer',
    }
  );

  fs.writeFileSync(outputPath, response.data);
  console.log('PDF converted to Word successfully!');
}

convertPdfToWord('./input.pdf', './output.docx');

4Run the Script

Execute your script with Node.js. The output.docx file will appear in the same directory.

bash
node convert-pdf.js

5Handle Errors

Always wrap your API calls in try/catch to handle network errors, invalid API keys (401), or rate limiting (429).

javascript
try {
  await convertPdfToWord('./input.pdf', './output.docx');
} catch (error) {
  if (error.response?.status === 401) {
    console.error('Invalid API key. Check your Authorization header.');
  } else if (error.response?.status === 429) {
    console.error('Rate limit exceeded. Upgrade to Pro for unlimited conversions.');
  } else {
    console.error('Conversion failed:', error.message);
  }
}

That's it!

You've successfully integrated the Convert Fleet API. Check the API reference for the full list of parameters and error codes.

Related API Endpoints

More Integration Guides

Start Building Today

Free tier includes 200 free credits (valid 30 days from signup). Pro plan unlocks unlimited API access.