PDF Squeezer API Sign Up

Node.js PDF Compression API

Use the PDF Squeezer PDF compression REST API from Node.js. Upload a PDF with fetch (or axios) and receive an optimized file.

const fs = require('fs');
const path = require('path');
const FormData = require('form-data');
const fetch = require('node-fetch');

const API_KEY = process.env.PDF_SQUEEZER_KEY;
const API_URL = 'https://api.pdfsqueezer.io/v1/compress';

async function compressPdf(inputPath, outputPath) {
  const form = new FormData();
  form.append('file', fs.createReadStream(inputPath), { filename: path.basename(inputPath) });
  form.append('quality', '85');
  form.append('maxDimension', '1600');
  form.append('stripMetadata', 'true');
  form.append('convertToJpeg', 'true');

  const response = await fetch(API_URL, {
    method: 'POST',
    headers: { ...form.getHeaders(), 'Authorization': `Bearer ${API_KEY}` },
    body: form
  });

  if (!response.ok) throw new Error(await response.text());
  const buffer = Buffer.from(await response.arrayBuffer());
  fs.writeFileSync(outputPath, buffer);
  console.log('Ratio:', response.headers.get('x-compression-ratio'));
}

Uses form-data and node-fetch. You can also use axios with a multipart form.

Full endpoint reference ยท Authentication

Get a free API key