Anyone knows how to extract text from pdf bytes in flutter web? The syncfusion_flutter_pdf package can do this but its not open source and To use this package, you need to have either a Syncfusion commercial license or Free Syncfusion Community license. So any other alternative?
I tried with js package to read typescript function from flutter web but when i try to import the pdf-parse library and then convert the file to ES5 javascript, the code is:
import * as PDFParser from 'pdf-parse';
async function extractTextFromPdf(pdfBytes: Uint8Array): Promise<string> {
try {
const pdfData = Buffer.from(pdfBytes);
const options = {}; // You can pass options here if needed
const data = await PDFParser(pdfData, options);
return data.text;
} catch (error) {
console.error('Error extracting text:', error);
throw new Error('Error extracting text');
}
}
and tried to convert this to ES5 with this command:
tsc --target ES5 extractPdfText.ts
then get the error shown below:
error TS1259: Module '"/pdf_extractor/node_modules/@types/pdf-parse/index"' can only be default-imported using the 'esModuleInterop' flag
1 import PdfParse from "pdf-parse";
~~~~~~~~
node_modules/@types/pdf-parse/index.d.ts:1:1
1 export = PdfParse;
~~~~~~~~~~~~~~~~~~
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
Found 1 error in PdfTextExtractorWeb.ts:1