getDocument is not a function
See original GitHub issueHi 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:
- Created 6 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top 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 >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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Please provide complete example.