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) PDFReader | null
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() object | null
Returns the next page, or null when there are no more pages. The page has:
pageNumber: the page's number, starting at1.lines: the page's text, as an array of lines.
readValues readValues() string[] | null
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() boolean
Returns true once the last page has been read, or when the PDF couldn't be opened or has no pages.
close close() optional
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);
}
}