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.

getDocument is not a function

See original GitHub issue

Hi guys, we love PDFJS here. It has been working great for awhile, but we’re upgrading all our js libraries and I just upgraded to the newest version yesterday.

Now I’m stuck.

I’m getting an error “PDFJS.getDocument is not a function”. I’ve tried setting the worker path and disabling the worker as suggested in other issues and neither helps. I’d rather not disable the worker if i don’t have to.

here is the failing code.

function load() {
	PDFJS.disableWorker = true;
	// Load PDFs one after another
	PDFJS.getDocument(urls[loadedCount]).then(function ( pdfDoc_ ) {
		pdfDocs = [];
		pdfDocs.push( pdfDoc_);
		totalPageCount = getTotalPageCount();
		form_item_input_div.append( $('<div id="page_container_'+ loadedCount +'"></div>').hide() );
		renderPage( 1 );
	}).catch( function (resp) {
		form_item_input_div.html($('<span type="text" class="t-text"/>').text( $.i18n._('ERROR: Unable to preview document...') ));
	} );
}

It’s probably worth mentioning that the documentation should have a section covering how to use pdfjs with require as digging through issues that are years old is not super helpful.

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
yurydelendikcommented, Oct 27, 2017

Where can i find an example of the latest code being used with require?

I don’t understand this question. require() is not a native JavaScript API method and shall be used in some context (with webpack or node.js).

Examples can be found at https://github.com/mozilla/pdf.js/tree/master/examples . You might need to check webpack or node examples.

Closing as answered.

1reaction
yurydelendikcommented, Oct 27, 2017

Please provide complete example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

getDocument(...).then is not a function #11960 - GitHub
The following code loads the PDF file successfully from a filepicker into a byte array, but fails PDF.js with Uncaught TypeError: pdfjsLib.
Read more >
pdf.js failing on getDocument - javascript - Stack Overflow
I get to answer my own question: the documentation isn't clear at all. If you don't define PDFJS.workerSrc to point to the correct ......
Read more >
How to use the pdfjs-dist.getDocument function in pdfjs-dist
const loadedPDFDocument = pdfjsLib.getDocument({ data, // Try to export JPEG images directly if they don't need any further // processing.
Read more >
Examples
A general-purpose, web standards-based platform for parsing and rendering PDFs.
Read more >
PDF.js 'Hello, world!' example - JSFiddle - Code Playground
Asynchronous download of PDF. 12. var loadingTask = pdfjsLib.getDocument(url);. 13. loadingTask.promise.then(function(pdf) {. 14. console.log('PDF loaded');.
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