I am trying to reference PDF.js (by Mozilla) into my React project. However, it is throwing 'Unexpected identifier' error.
I have placed the PDF.js in the public folder and referenced it in my index.html.
File structure:
public
- index.html
- pdftojs
- parsejs.js // < parseFile method in this file will be called
- pdf-parse.js
- misc..
src
- pdftotext
- parsepdf.js // < page to parse PDF
pdf-parse.js
var PDFJS = null
function render_page(pageData) { ... } // Untouched
async function PDF(...) { ... } // Untouched
exports.pdf = PDF; // Changed this line
parsejs.js from the original library:
8 import pdf from 'pdf-parse.js';
9 const pdfjsLib = require('pdfjs-dist'); // 'require' is undefined too so I don't know what is the correct way
10
11 function parseFile(file) {
...
45 }
This file throws Unexpected identifier on Line 8
Parse PDF Page (parsepdf.js)
process(file) {
parseFile(file); // calling method in parsejs.js
...
}
which gives 'parseFile' is not defined