---
url: /process-functions/pdf-reader.md
description: Reads a PDF file one page at a time.
---

# &#x20;PDFReader

Reads a PDF file one page at a time.

```js
const reader = datasource.pdfRead("uploads/invoice.pdf");

while (!reader.isEOF()) {
    const page = reader.read();
    console.log("Page " + page.pageNumber + ": " + page.lines.join(" "));
}
```

## Constructor

### datasource.pdfRead `datasource.pdfRead(fileName)`  {#datasource-pdfread}

Opens a PDF file, or returns `null` when the path is invalid.

| Parameter | Type | Description |
|---|---|---|
| `fileName` | `string` | The path of the PDF file. |

```js
const reader = datasource.pdfRead("uploads/invoice.pdf");
```

## Methods

### read `read()`  {#read}

Returns the next page, or `null` when there are no more pages. The page has:

* `pageNumber`: the page's number, starting at `1`.
* `lines`: the page's text, as an array of lines.

### readValues `readValues()`  {#readvalues}

Returns the next page's text as an array of lines, or `null` when there are no more pages. Use it when you don't need the page number.

### isEOF `isEOF()`  {#iseof}

Returns `true` once the last page has been read, or when the PDF couldn't be opened or has no pages.

### close `close()`  {#close}

Closes the PDF. Readers close automatically when the process finishes, so only call this to release the file early.

## Examples

### Read every page

```js
const reader = datasource.pdfRead("uploads/report.pdf");

while (!reader.isEOF()) {
    const page = reader.read();
    console.log("Page " + page.pageNumber + " has " + page.lines.length + " lines");
}
```

### Read every line

```js
const reader = datasource.pdfRead("uploads/statement.pdf");

while (!reader.isEOF()) {
    for (const line of reader.readValues()) {
        console.log(line);
    }
}
```
