import { fs } from "@llamaindex/env";
import { Document } from "../Node.js";
import { FileReader } from "./type.js";
/**
 * Read the text of a PDF
 */ export class PDFReader extends FileReader {
    async loadData(file) {
        const content = await 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 Document({
                text,
                metadata
            });
        });
    }
}
async function readPDF(data) {
    const { extractText } = await import("unpdf");
    return await extractText(data);
}
