Menu

Post image 1
Post image 2
1 / 2
0

How to Compress PDFs via REST API — curl, Node.js & Python Examples

DEV Community·Forgelab Africa·27 days ago
#QcyglC3v
Reading 0:00
15s threshold

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 "file=@report.pdf" \ --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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More