将PDF.js查看器与React.js库一起使用时未捕获(承诺)错误?

时间:2019-03-31 09:18:59

标签: reactjs pdf.js

我安装了pdfjs-dist,并尝试使用以下组件将其导入react并与import React, { Component } from 'react' import * as pdfjs from 'pdfjs-dist' class App extends Component { componentDidMount() { pdfjs.getDocument('./sample.pdf').promise.then(doc => console.log(doc.numPages)) } render() { return <div>test pdf</div> } } export default App 一起使用:

Uncaught (in promise) Error: Setting up fake worker failed: "Cannot read property 'WorkerMessageHandler' of undefined".

但是我在控制台遇到下一个错误

import pdfjs from 'pdfjs-dist/webpack'

我也尝试将import语句更改为:

Uncaught ReferenceError: window is not defined

但是我得到了这个错误:

[Time("'{obj.EventId}'")] private static void testFody(TestClass obj) { for (int i = 0; i < 100; i++) { Console.WriteLine($"This is : {i }"); } } public class TestClass { public Guid EventId { get; set; } public string prop1 { get; set; } public int prop2 { get; set; } }

1 个答案:

答案 0 :(得分:1)

我认为您需要根据讨论here和示例here

pdfjsrequire一起导入