---
title: Engine
description: Open, read, change and save PDF files from JavaScript, with one typed API.
---
import { Cards, Card } from '@/components/docs/cards';
# The PDF engine
The EmbedPDF engine opens PDF files in the browser and lets you render their pages, read and
search their text, add annotations, fill forms, edit pages and save the result. It runs
[EmbedPDF Runtime](https://github.com/embedpdf/runtime), our fork of PDFium, the PDF library
inside Chrome, in a Web Worker, so your page stays responsive. Nothing is uploaded: the file never
leaves the device.
The ready-made 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.
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 { localEngine } from '@embedpdf/engine';
const engine = localEngine();
const doc = await engine.open({ kind: 'bytes', bytes });
const { pages } = await doc.pages.list();
const image = await doc.page(pages[0].ref).render.image();
```
```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](/docs/engine/documents/rendering)** as images, at any size.
- **[Read](/docs/engine/text/extraction), [search](/docs/engine/text/search) and
[select](/docs/engine/text/selection-and-geometry)** the text on a page, and find out where
each character is.
- **[Add and edit annotations](/docs/engine/annotations)**: highlights, notes, shapes, stamps,
measurements. Copy them to another document with
[import & export](/docs/engine/annotations/import-export).
- **[Fill forms](/docs/engine/forms)**, create form fields and
[sign](/docs/engine/forms/signatures) documents.
- **[Change pages](/docs/engine/documents/pages)**: rotate, reorder, delete, insert, merge and
split.
- **[Redact](/docs/engine/documents/redaction)** content for good, and
**[save](/docs/engine/documents/saving)** the result.
- **[Group edits into changes](/docs/engine/documents/changes)** 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.
{/* readme: end */}
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 '@embedpdf/engine';
if (isLocalDocument(doc)) {
const layer = await doc.downloadLayer();
}
```
`isLocalEngine(engine)` does the same for an engine.
## Local or cloud
This engine runs in the browser: no server, no upload, and it works offline. That makes it the
right choice when the user already has the file, or when the file may not leave their device.
When the file lives on your server, the CloudPDF engine runs the same API there and checks every
call. A user sees the first page as an image, without downloading the whole PDF or the engine
(about 3 MB compressed), and a user who may not download the file never receives it. Your code
stays the same: swap `localEngine()` for `cloudEngine()`.
## Next steps