> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chromiumly.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Render and extract

> Draw PDF pages as images, extract their text, and shrink PDFs.

## Render

`render` draws pages as images. `PDF.render()` returns the images alone: one image, or a ZIP of several (`report_1.png`, …). As the last stage of a list, `render` returns them in a ZIP next to the PDF.

| Option | Type | Description |
| - | - | - |
| `pages` | pages | The pages to draw (default `all`) |
| `dpi` | `number` | The resolution, at least 1 (default `150`) |
| `format` | `string` | `"png"` (default) or `"jpeg"` |
| `quality` | `number` | `jpeg` only, from 1 to 100 (default `100`); refused with `png` |

```typescript theme={null}
import { PDF } from "chromiumly";

const thumbnail = await PDF.render({
  files: ["path/to/report.pdf"],
  pages: "1",
  dpi: 72,
  format: "jpeg",
  quality: 80,
});
```

To capture a web page as an image directly, use the Chromium [screenshots](https://docs.chromiumly.dev/chromium/overview.md) instead.

## Extract text

`extract-text` returns the text the pages show, as a `.txt` file whose pages are separated by a form feed. `PDF.extractText()` returns the text alone; as the last stage of a list, it comes back in a ZIP next to the PDF.

| Option | Type | Description |
| - | - | - |
| `pages` | pages | The pages to read, in the order given (default `all`) |
| `invisible` | `boolean` | Adds the text layer a searchable scan carries under its image (default `false`) |
| `artifacts` | `boolean` | Adds headers, footers, page numbers and stamps the PDF marks as artifacts (default `false`) |
| `annotations` | `boolean` | Adds the text of annotations, such as comments (default `false`) |

```typescript theme={null}
const text = await PDF.extractText({ files: ["path/to/report.pdf"], pages: "1-2" });
console.log(text.toString("utf8"));
```

Gotenberg recognizes no text in an image: a scan without a text layer extracts nothing.

## Optimize

`optimize` rewrites the PDF to shrink it. Every option is on unless you turn it off, and it keeps the quality of every image.

| Option | Description |
| - | - |
| `objectStreams` | Packs objects into compressed object streams |
| `dedup` | Stores identical streams once |
| `recompressImages` | Recompresses images without losing quality |
| `subsetFonts` | Keeps only the glyphs the document shows |

```typescript theme={null}
const smaller = await PDF.optimize({ files: ["path/to/report.pdf"] });
```

A signed PDF is refused, and so is an encrypted one unless the stages decrypt or encrypt it. To lower image quality, do it where the PDF is made: LibreOffice's `nativeQuality` and `nativeReduceImageResolution`, or smaller images in the HTML you send Chromium.

See [Reference — PDF](https://docs.chromiumly.dev/reference/pdf.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.