- HTML to PDF APIConvert HTML and URLs into PDFsExtract PDF Form Data APIEasily extract data from PDFsWatermark PDF APIAdd custom watermarks to PDFsProtect PDF APISecure your PDFs with passwordCompress PDF APIReduce file size without losing qualityFlatten PDF APIFlatten PDFs to make form permanentDigital Signature APISend documents for signing
- API DocumentationAPI DocumentationFull REST API referenceNodeJS SDKClient library for Node.jsJava SDKClient library for JavaC# SDKClient library for C#PHP SDKClient library for PHPPython SDKClient library for Python
- Pricing
- Contact Us

Compress PDF API
Reduce PDF file size while preserving visual quality.
1const fs = require("fs/promises");23(async () => {4 const form = new FormData();56 const bytes = await fs.readFile("YOUR_FILE.pdf");7 const file = new File([bytes], "YOUR_FILE.pdf", { type: "application/pdf" });8 form.append("file", file);9 form.append("linearize", "true");1011 const res = await fetch("https://api.pdfgate.com/compress/pdf", {12 method: "POST",13 body: form,14 headers: { Authorization: "Bearer YOUR_API_KEY" },15 });1617 if (res.status === 201) {18 const buf = Buffer.from(await res.arrayBuffer());19 await fs.writeFile("compressed.pdf", buf);20 } else {21 const text = await res.text();22 console.error(text);23 }24})();Compress PDF API Overview
The Compress PDF API allows you to optimize PDF file size as part of an automated document workflow. It is designed for scenarios where PDFs need to be reduced in size before being uploaded, shared, or stored.
Compressing PDFs helps improve performance by reducing download times and storage requirements while keeping documents readable and visually consistent. This is commonly used when working with large files, image-heavy documents, or high-resolution PDFs.
This endpoint can be used on its own or combined with other PDFGate endpoints. A typical workflow includes generating a PDF from HTML, applying compression to optimize file size, and then distributing or storing the optimized document.
The Compress PDF API is well suited for SaaS platforms, internal systems, and document automation workflows that require efficient handling of PDFs without manual optimization steps.
Useful Guides
View All Guides ↗API Parameters
File
FileThe PDF file you want to compress. You must provide either this or documentId.
Document Id
StringThe ID of a PDF that already exists in your PDFGate account. Use this instead of uploading a file again.
Linearize
BoolRe-arranges the PDF structure so the first page can be displayed before the entire file has finished downloading.
Json Response
BoolIf it is set to true, the API will return a JSON response instead of the PDF file.
Pre Signed Url Expires In
NumberExpiration time (in seconds) for the generated temporary download URL.
Metadata
ObjectCustom metadata you want to attach to the document.
Start building with PDFGate today
Generate PDFs, send documents for signature, and automate your document workflows in minutes.
Free trial · No credit card required




