错误“rangeerror:超出最大调用堆栈大小” [英] Error "rangeerror: maximum call stack size exceeded"

查看:547
本文介绍了错误“rangeerror:超出最大调用堆栈大小”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PDF.js从pdf文件获取表单数据但是出现了上述错误。我从此处 [ ^ ]



我的尝试:



 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); //在这里得到错误

});
});

解决方案

请参阅 Function.prototype.apply() - JavaScript | MDN [ ^ ]:

Quote:

apply()方法调用一个给定的函数作为数组提供的值和参数。

这意味着调用 String.fromCharCode 的参数与数组中的项目一样多。但是可以传递给函数的最大参数数量(通常约为64k)存在限制。您已达到此限制,由错误消息指示。



解决方案:

使用循环调用 String.fromCharCode 为每个数组元素或使用文本解码器(例如 TextDecoder(utf-8)。decode(arrayBuffer))。


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
                
                });
            });

解决方案

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)).


这篇关于错误“rangeerror:超出最大调用堆栈大小”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆