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

# TypeScript / Node.js API Usage

> Use PdfItDown in your Node.js or TypeScript project through NAPI-RS bindings

The `@cle-does-things/pdfitdown` package provides native Node.js bindings to the Rust PdfItDown engine via [NAPI-RS](https://napi.rs).

## Installation

```bash theme={null}
npm install @cle-does-things/pdfitdown
# or
yarn add @cle-does-things/pdfitdown
```

Prebuilt binaries are available for macOS (x86\_64, arm64), Linux (x86\_64, arm64, musl), and Windows (x86\_64, arm64).

## Supported Formats

| Category | Formats                                            |
| -------- | -------------------------------------------------- |
| Markup   | `.md`, `.html`, `.htm`                             |
| Office   | `.docx`, `.xlsx`, `.pptx`                          |
| Images   | `.png`, `.jpg`, `.jpeg`, `.webp`, `.tiff`, `.avif` |
| Text     | `.txt`, `.csv`, `.xml`, `.json`, and more          |
| Other    | `.pdf` (pass-through)                              |

## API

```typescript theme={null}
import { PdfItDownConverter } from '@cle-does-things/pdfitdown'

const converter = new PdfItDownConverter()
```

### Convert a single file

```typescript theme={null}
converter.convertFile('input.docx', 'output.pdf', true)
```

### Convert multiple files

```typescript theme={null}
converter.convertMultipleFiles(
  ['file1.docx', 'file2.pptx'],
  ['file1.pdf', 'file2.pdf'],
  true // overwrite existing
)
```

### Convert a directory

```typescript theme={null}
converter.convertDirectory('./documents', true, true) // overwrite, recursive
```

### Convert from memory (Buffer → Buffer)

```typescript theme={null}
import { readFileSync, writeFileSync } from 'fs'

const input = readFileSync('input.docx')
const output = converter.convertBytes(input)
writeFileSync('output.pdf', output)
```

## Type definitions

```typescript theme={null}
class PdfItDownConverter {
  constructor()

  /** Convert a file on disk. */
  convertFile(inputFile: string, outputFile: string, overwrite: boolean): void

  /** Convert multiple files in one call. */
  convertMultipleFiles(inputFiles: string[], outputFiles: string[], overwrite: boolean): void

  /** Convert all supported files in a directory. */
  convertDirectory(directory: string, overwrite: boolean, recursive: boolean): void

  /** Convert a Buffer in memory and return a PDF Buffer. */
  convertBytes(input: Buffer): Buffer
}
```
