- 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

Flatten PDF API
Convert fillable PDF forms into static, non-editable documents.
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);910 form.append("jsonResponse", "false");11 form.append("metadata", JSON.stringify({12 author: "John Doe",13 documentType: "Contract",14 }));1516 const res = await fetch("https://api.pdfgate.com/forms/flatten", {17 method: "POST",18 body: form,19 headers: { Authorization: "Bearer YOUR_API_KEY" },20 });2122 if (res.status === 201) {23 const buf = Buffer.from(await res.arrayBuffer());24 await fs.writeFile("flattened.pdf", buf);25 } else {26 const text = await res.text();27 console.error(text);28 }29})();30Flatten PDF API Overview
The Flatten PDF API turns the form fields in a PDF into ordinary page content. Every text field, checkbox, radio button, dropdown and text area is drawn onto the page with its current value, and the interactive form is removed. The result looks the same in any reader, but nothing in it can be edited, and software that inspects the file no longer finds a form.
Send the PDF as a file upload or pass the ID of a document already stored in PDFGate. The API returns a new document and leaves the original untouched, so you can keep the fillable version and the locked version side by side. Pass a list of field names to flatten only those fields and keep the rest of the form interactive, for example to lock a customer ID or a signature while the remaining fields stay open.
Flattening usually sits at the end of a workflow. Generate a form from HTML, let someone fill it in, read the submitted values, then flatten the document before it is archived, printed or emailed. Add password protection or compression to the flattened file if you need them. Documents completed through the Digital Signature API are flattened for you.
Flattening is not the same as protecting a PDF. A password-protected file still contains the form, and a flattened file has none. Flatten first, then protect, if you want both.
API Parameters
File
FileThe PDF file you want to flatten. 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.
Field Names
ArrayNames of the fields to flatten. When it is not provided, all form fields are flattened.
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




