Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

javascript - pdf viewer component cannot load images

  pdfjsLib.getDocument({data: this.props.pdfData}).then((pdf) => {
      this.setState({pdf: pdf});
    });

I have changed the above block of code to

var loadingTask = pdfjsLib.getDocument({ data: this.props.pdfData });
    loadingTask.promise.then((pdf) => {
      this.setState({ pdf: pdf });
    });

because I was getting

pdfViewer.jsx?5761:28 Uncaught TypeError: pdfjsLib.getDocument(...).then is not a function

after that my page loads without any errors but am getting CSS NAN if change renderPages function canvas.width and canvas.height to some value pages are loading but pdf is looking wired

  _renderPage(page) {
const { scale } = this.context;
const viewport = page.getViewport(scale);
const { width, height } = viewport;
const canvas = this.canvas.current;
const context = canvas.getContext('2d');
canvas.width = width;
canvas.height = height;

page.render({
  canvasContext: context,
  viewport,
});

this.setState({ status: 'rendered', page, width, height });
}

Any suggestions

question from:https://stackoverflow.com/questions/65838870/pdf-viewer-component-cannot-load-images

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...