Skip to main content
GuideNode.js

PDF to Image API Example in Node.js

Convert PDF pages to JPG images using the Convert Fleet REST API in Node.js. Ideal for document previews, thumbnails, and report generation.

LanguageNode.js
Conversionpdfjpg
API ReferenceView Endpoint →

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

1Install Dependencies

Install axios and form-data.

bash
npm install axios form-data

2Convert PDF to JPG

Use the Convert Fleet API to render each PDF page as a JPG image.

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

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

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

  // Multi-page PDFs return a ZIP file
  const isZip = response.headers['content-type']?.includes('zip');
  const ext = isZip ? '.zip' : '.jpg';
  fs.writeFileSync(outputPath.replace('.jpg', ext), response.data);
  console.log(`PDF converted: ${outputPath}`);
}

convertPdfToJpg('./document.pdf', './preview.jpg');

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.