# Compress and reduce PDF file size

You can compress PDFs using Document Engine.

## Compressing PDFs

To compress a PDF, use the following example:

### SHELL

```shell

curl -X POST http://localhost:5000/api/build \
  -H "Authorization: Token token=<API token>" \
  -F document=@/path/to/example-document.pdf \
  -F instructions='{
  "parts": [
    {
      "file": "document"
    }
  ],
  "output": {
    "type": "pdf",
    "optimize": {
      "grayscaleText": true,
      "grayscaleGraphics": true,
      "grayscaleFormFields": true,
      "grayscaleAnnotations": true,
      "disableImages": true,
      "mrcCompression": true,
      "imageOptimizationQuality": 2
    }
  }
}' \
  -o result.pdf

```

### HTTP

```http

POST /api/build HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary
Authorization: Token token=<API token>

--customboundary
Content-Disposition: form-data; name="document"; filename="example-document.pdf"
Content-Type: application/pdf

<PDF data>
--customboundary
Content-Disposition: form-data; name="instructions"
Content-Type: application/json

{
  "parts": [
    {
      "file": "document"
    }
  ],
  "output": {
    "type": "pdf",
    "optimize": {
      "grayscaleText": true,
      "grayscaleGraphics": true,
      "grayscaleFormFields": true,
      "grayscaleAnnotations": true,
      "disableImages": true,
      "mrcCompression": true,
      "imageOptimizationQuality": 2
    }
  }
}
--customboundary--

```

### Font subsetting during optimization

When you compress PDFs using Document Engine’s optimization feature, font subsetting is automatically applied to existing embedded fonts. This reduces file size by including only the characters actually used in the document, rather than the entire font.

**Key points**

Font subsetting:

- Is enabled by default during optimization.

- Works with most modern fonts (some complex fonts may not be subsetted).

- Only occurs when using the optimization features (not during simple document modifications).

- Requires no additional configuration — font subsetting happens automatically when you use the [`optimize`](https://www.nutrient.io/api/reference/document-engine/upstream/#tag/Import-and-Export/operation/download-document-pdf) parameter when downloading a PDF.

## Licensing

To compress PDFs with Document Engine, the [Compression feature](https://www.nutrient.io/guides/web/about/capability-and-component-comparison-document-engine.md) needs to be included in your license. [Contact sales](https://www.nutrient.io/company/contact) to add the feature to your license.

After the new component is added to your license, update the license or activation keys in your configuration.

## Linearization

You can perform both linearization and compression in a single request to `/api/build` if both features are enabled in your license:

```json

instructions = {...
  output: {
    type: "pdf",
    optimize: {
      grayscaleText: true,
      grayscaleGraphics: true,
      grayscaleFormFields: true,
      grayscaleAnnotations: true,
      disableImages: true,
      mrcCompression: true,
      imageOptimizationQuality: 2,
      linearize: true,
    }
  }
}

```

To learn more about linearization with Document Engine, refer to the [linearization](https://www.nutrient.io/guides/document-engine/optimization/linearize.md) guide.
---

## Related pages

- [Hyper-compress](/guides/document-engine/optimization/hyper-compress.md)
- [PDF annotation flattening](/guides/document-engine/optimization/flatten.md)
- [PDF compressor server](/guides/document-engine/optimization.md)
- [Create linearized PDFs](/guides/document-engine/optimization/linearize.md)

