If your app needs to compress PDFs, you have two paths:
Install pdf-lib , ghostscript , or puppeteer — and inherit binary dependencies, config complexity, and memory overhead.
Make one HTTP POST and let a dedicated API handle it.
Here's how the second option works with the Forgelab PDF API.
The endpoint
POST https://www.forgelab.africa/api/pdf/compress
Enter fullscreen mode
Exit fullscreen mode
Headers: X-API-Key: your_api_key
Body (multipart/form-data): file — the PDF to compress
Response: compressed PDF as a binary download.
curl
curl -X POST https://www.forgelab.africa/api/pdf/compress \ -H "X-API-Key: $FORGELAB_API_KEY " \ -F "[email protected]" \ --output compressed.pdf
Enter fullscreen mode
Exit fullscreen mode
A 10 MB PDF typically comes back under 2 MB.
Node.js
import fs from ' fs ' ; import fetch from ' node-fetch ' ; import FormData from ' form-data ' ;
async function compressPdf ( inputPath , outputPath ) { const form = new FormData (); form . append ( ' file ' , fs .…