---
title: "Engine"
description: "Open, read, change and save PDF files from JavaScript, with one typed API."
source: "https://www.cloudpdf.com/docs/engine"
---

# The PDF engine

The CloudPDF engine gives your app a full PDF engine over HTTPS. Your files stay on your
CloudPDF server. The engine renders their pages, reads and searches their text, stores
annotations and form values, and checks every call against the permissions in the user's
token.

The CloudPDF viewer and the headless components are built on this engine. Use it directly when
you want PDF features without a viewer: a thumbnail job, a form filler, an export script.

```ts
import { cloudEngine } from '@cloudpdf/engine';

const engine = cloudEngine();
const doc = await engine.open({ kind: 'token', token: () => fetchDocumentToken(documentId) });

const { pages } = await doc.pages.list();
const image = await doc.page(pages[0].ref).render.image();
```

## What you can do

- **[Render pages](https://www.cloudpdf.com/docs/engine/documents/rendering.md)** as images, at any size.
- **[Read](https://www.cloudpdf.com/docs/engine/text/extraction.md), [search](https://www.cloudpdf.com/docs/engine/text/search.md) and
  [select](https://www.cloudpdf.com/docs/engine/text/selection-and-geometry.md)** the text on a page, and find out where
  each character is.
- **[Add and edit annotations](https://www.cloudpdf.com/docs/engine/annotations.md)**: highlights, notes, shapes, stamps,
  measurements. Copy them to another document with
  [import & export](https://www.cloudpdf.com/docs/engine/annotations/import-export.md).
- **[Fill forms](https://www.cloudpdf.com/docs/engine/forms.md)**, create form fields and
  [sign](https://www.cloudpdf.com/docs/engine/forms/signatures.md) documents.
- **[Change pages](https://www.cloudpdf.com/docs/engine/documents/pages.md)**: rotate, reorder, delete, insert, merge and
  split.
- **[Redact](https://www.cloudpdf.com/docs/engine/documents/redaction.md)** content for good, and
  **[save](https://www.cloudpdf.com/docs/engine/documents/saving.md)** the result.
- **[Group edits into changes](https://www.cloudpdf.com/docs/engine/documents/changes.md)** that apply all or none, and undo
  or redo any of them.

Every call is async, can be cancelled, and fails with a typed error you can branch on. The same
code runs on the local engine and on the CloudPDF engine: only how you create the engine and
open a file differs.

A few things exist only on the local engine: its fonts, `warmup()`, raw pixels, and saving a
document's layer or to a file. A document opened with `localEngine()` has them. Code that takes
any engine checks first:

```ts
import { isLocalDocument } from '@cloudpdf/engine';

if (isLocalDocument(doc)) {
  const layer = await doc.downloadLayer();
}
```

`isLocalEngine(engine)` does the same for an engine.

## Next steps

- [Quick start](https://www.cloudpdf.com/docs/engine/quick-start.md) — Open a PDF, render a page, search it and add a highlight.
- [Setup](https://www.cloudpdf.com/docs/engine/setup.md) — Install the engine and create it once for your app.
- [Annotations](https://www.cloudpdf.com/docs/engine/annotations.md) — Read, add and change annotations of every kind.
