I'm trying to upload a pdf file then I need to parse it using pdf2json without saving the file in the directory but pdf2json requests a directory path in loadPDF. any idea what can I do, please?
https://www.npmjs.com/package/pdf2json
@Post('getFields')
@UseInterceptors(AzureStorageFileInterceptor('file'))
@UploadedFile() file?: UploadedFileMetadata){
if (!file || Object.keys(file).length === 0 ||file.constructor !== Object) {
throw UtilError.createErrorError('Missing file.');
}
const pdfParser = new PDFParser(file);
pdfParser.on("pdfParser_dataError", errData => console.error(errData.parserError) );
pdfParser.on("pdfParser_dataReady", pdfData => {
fs.writeFile(path.join(__dirname, './../../../../src/entities/skiplino/form/F1040EZ.json'), JSON.stringify(pdfData), function(){ console.log("done!") }
);
});
return await pdfParser.loadPDF(./../file);
}
Just use pdfParser.parseBuffer(pdfBuffer); and pass in the file buffer.
You'll need to use the built in File Interceptor instead of the AzureStorageFileInterceptor