Attach (recommended) or Link to PDF file here:
Configuration:
Operating system and its version:
Win 7 Sp1
PDF.js version:
2.0.943
Is a browser extension:
No
Steps to reproduce the problem:
<script>
// Path to PDF file
var PDF_URL = 'web/mandado_1.pdf';
// Specify the path to the worker
PDFJS.workerSrc = 'build/pdf.worker.js';
/*
/* Retrieves the text of a specif page within a PDF Document obtained through pdf.js
*
* @param {Integer} pageNum Specifies the number of the page
* @param {PDFDocument} PDFDocumentInstance The PDF document obtained
**/
function getPageText(pageNumber, PDFDocumentInstance) {
// Return a Promise that is solved once the text of the page is retrieven
return new Promise(function (resolve, reject) {
PDFDocumentInstance.getPage(pageNum).then(function (pdfPage) {
// The main trick to obtain the text of the PDF page, use the getTextContent method
pdfPage.getTextContent().then(function (textContent) {
var textItems = textContent.items;
var finalString = "";
// Concatenate the string of the item to the final string
for (var i = 0; i < textItems.length; i++) {
var item = textItems[i];
finalString += item.str + " ";
}
// Solve promise with the text retrieven from the page
resolve(finalString);
});
});
});
}
PDFJS.getDocument(PDF_URL).then(function (PDFDocumentInstance) {
// Use the PDFDocumentInstance To extract the text later
}, function (reason) {
// PDF loading error
console.error(reason);
});
</script>
`
What is the expected behavior? (add screenshot)
show converted text
What went wrong? (add screenshot)
the error above in title:
Uncaught ReferenceError: PDFJS is not defined
Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):
The global PDFJS
object is removed in version 2.0, so the tutorial you're using is out of date for that version. Refer to the examples
folder for how to use PDF.js 2.0, for example https://github.com/mozilla/pdf.js/blob/master/examples/learning/helloworld.html.
i just download pdf.js 1.9 version and this code worked . You can use this code with old pdf.worker.js