Как ссылаться на библиотеку pdf.js в React? - PullRequest
0 голосов
/ 27 марта 2019

Я пытаюсь сослаться PDF.js (от Mozilla) на мой проект React.Тем не менее, он выдает ошибку «Неожиданный идентификатор».

Я поместил PDF.js в общую папку и сослался на него в моем index.html.

Структура файла:

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 из исходной библиотеки:

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   }

Этот файл выдает Unexpected identifier on Line 8

Parse PDF Page (parsepdf.js)

  process(file) {
     parseFile(file); // calling method in parsejs.js
     ...
  }

, что дает 'parseFile' is not defined

...