Click here to Skip to main content
15,891,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to get form data from pdf file using PDF.js but got above error.I have downloaded the pdf.js file from Here[^]

What I have tried:

var tmppath = URL.createObjectURL(document.getElementById('flupd').files[0]);
      PDFJS.workerSrc = "js/pdf.worker.js";
      PDFJS.getDocument(tmppath).then(function getPdfHelloWorld(pdf) {
         
      pdf.getData().then(function (arrayBuffer) {                  
      var pdfraw = String.fromCharCode.apply(null, arrayBuffer);  //getting error here
                
                });
            });
Posted
Updated 14-Mar-17 1:42am
v3

1 solution

See Function.prototype.apply() - JavaScript | MDN[^]:
Quote:
The apply() method calls a function with a given this value and arguments provided as an array.
That means that String.fromCharCode is called with so many arguments as there are items in the array. But there is a limitation for the maximum number of arguments that can be passed to a function (usually about 64k). You have hit this limit which is indicated by the error message.

Solution:
Use a loop to call String.fromCharCode for each array element or use a text decoder (e.g. TextDecoder("utf-8").decode(arrayBuffer)).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900