question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Cannot resolve callback 1 when opening multiple pdfs

See original GitHub issue

Link to PDF file (or attach file here):

pdf-sample.pdf compressed.tracemonkey-pldi-09.pdf

Configuration:

  • Web browser and its version: Chrome 56.0.2924.87
  • Operating system and its version: OSX 10.11.6
  • PDF.js version: pdfjs-dist 1.7.414
  • Is an extension: No

Using following React component:

import React, { Component } from 'react';
import PDFJS from 'pdfjs-dist/webpack';

class App extends Component {
  constructor() {
    super();
    this.state = {pdfs: []};
    this.handleInputChange = this.handleInputChange.bind(this);
  }

  handleInputChange(event) {
    const file = event.target.files[0];
    const reader = new FileReader();
    const self = this;
    reader.onload = function() {
      const typedArray = new Uint8Array(this.result);
      PDFJS.getDocument(typedArray).then(pdf => {
        self.setState({pdfs: self.state.pdfs.concat(pdf)});
      });
    };
    reader.readAsArrayBuffer(file);
  }

  render() {
    return (
      <div>
        <input type="file" onChange={this.handleInputChange}/>
        <ul>
          {this.state.pdfs.map((pdf, i) => <li key={i}>{pdf.numPages}</li>)}
        </ul>
      </div>
    );
  }
}

Steps to reproduce the problem:

  1. Upload first attached PDF
  2. Upload second attached PDF

What is the expected behavior? Both PDFs’ page counts are printed:

image

What went wrong? The expected behavior occurs, but PDF.js throws the following error when a second PDF is opened, and will throw the error again whenever a new PDF is opened:

Error: Cannot resolve callback 1
pdf.js:340     at error (http://localhost:3000/static/js/bundle.js:33026:18)
    at MessageHandler.messageHandlerComObjOnMessage (http://localhost:3000/static/js/bundle.js:33732:10)

(specifically, from line https://github.com/mozilla/pdf.js/blob/59392fd5442d819879dc7ec0a0a8ce9a2fbd2f71/src/shared/util.js#L1291)

This appears unrelated to the contents of the PDFs, this occurs with any sequence of multiple PDFs I’ve tried other than opening the same file twice.

If I call pdf.destroy() on the already-open PDF before opening another, this does not occur.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gdaolewecommented, May 26, 2017

@yurydelendik I published a complete minimal project here: https://github.com/gdaolewe/webpack-pdfjs-repro

0reactions
yurydelendikcommented, May 19, 2017

@rvinay88 @mattnetto can you publish complete project (instead of snippets of code)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to display pdf file using react-pdf - Stack Overflow
I managed to resolve my issue. The issue seemed to happen due to a variable assignment to the window object at a completely...
Read more >
Resolve Acrobat intermittent crashes on Windows
Solution 2: Run Repair Acrobat Installation while no other applications are running · Close all open applications. · Open Acrobat. · Choose Help...
Read more >
A Comprehensive Guide To Error Handling In Node.js
Errors happen in every application. Devs have to decide: do you write code to handle the error? Suppress it? Notify the user?
Read more >
Error handling with promises - The Modern JavaScript Tutorial
Promise chains are great at error handling. When a promise rejects, the control jumps to the closest rejection handler.
Read more >
replace-in-file - npm
A simple utility to quickly replace text in one or more files. ... callbacks for to; Ignore a single file or glob; Ignore...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found