"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "PDFReader", {
    enumerable: true,
    get: function() {
        return PDFReader;
    }
});
const _env = require("@llamaindex/env");
const _Node = require("../Node.js");
const _type = require("./type.js");
class PDFReader extends _type.FileReader {
    async loadData(file) {
        const content = await _env.fs.readFile(file);
        return this.loadDataAsContent(new Uint8Array(content.buffer));
    }
    async loadDataAsContent(content) {
        const { totalPages, text } = await readPDF(content);
        return text.map((text, page)=>{
            const metadata = {
                page_number: page + 1,
                total_pages: totalPages
            };
            return new _Node.Document({
                text,
                metadata
            });
        });
    }
}
async function readPDF(data) {
    const { extractText } = await import("unpdf");
    return await extractText(data);
}
