我正在尝试编写一个chrome扩展来实现PDFJS从PDF中提取数据。我可以在读取本地文件时实现这一点,但我希望在浏览器中解析当前正在查看的PDF。
我收到了大量的以下错误:
'Warning: Ignoring invalid character "33" in hex string'
'Warning: Ignoring invalid character "79" in hex string'...然后
"Error
at InvalidPDFExceptionClosure (chrome-extension://nhbmpffpjhndjdpmlahapejappacnkcc/pdfjs/pdf.js:658:35)
at Object.<anonymous> (chrome-extension://nhbmpffpjhndjdpmlahapejappacnkcc/pdfjs/pdf.js:661:2)
at __w_pdfjs_require__ (chrome-extension://nhbmpffpjhndjdpmlahapejappacnkcc/pdfjs/pdf.js:52:30)
at Object.<anonymous> (chrome-extension://nhbmpffpjhndjdpmlahapejappacnkcc/pdfjs/pdf.js:129:23)
at __w_pdfjs_require__ (chrome-extension://nhbmpffpjhndjdpmlahapejappacnkcc/pdfjs/pdf.js:52:30)
at chrome-extension://nhbmpffpjhndjdpmlahapejappacnkcc/pdfjs/pdf.js:116:18
at chrome-extension://nhbmpffpjhndjdpmlahapejappacnkcc/pdfjs/pdf.js:119:10
at webpackUniversalModuleDefinition (chrome-extension://nhbmpffpjhndjdpmlahapejappacnkcc/pdfjs/pdf.js:31:50)
at chrome-extension://nhbmpffpjhndjdpmlahapejappacnkcc/pdfjs/pdf.js:32:3"我找不出是什么导致了这个错误。
这是我用来打开PDF文档的代码
var url = decodeURIComponent(location.href.split('?url=')[1]);
//http://www.pdf995.com/samples/pdf.pdf
var params = {
cMapPacked: true,
cMapUrl: "pdfjs/cmaps/",
disableAutoFetch: false,
disableCreateObjectURL: false,
disableFontFace: false,
disableRange: false,
disableStream: false,
docBaseUrl: url,
isEvalSupported: true,
maxImageSize: -1,
pdfBug: false,
postMessageTransfers: true,
url: url,
verbosity: 1
};
pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs/pdf.worker.js';
var loadingTask = (0, pdfjsLib.getDocument)(params);
loadingTask.promise.then(...发布于 2019-07-29 18:15:49
捕获请求并重定向到扩展的background.js文件使用
chrome.webRequest.onBeforeRequest更改为
chrome.webRequest.onHeadersReceived已修复此问题。
我还更改了加载PDF的代码:
var loadingTask = pdfjsLib.getDocument({
url: url,
cMapUrl: "pdfjs/cmaps/",
cMapPacked: true
});
loadingTask.promise.then(...https://stackoverflow.com/questions/57219853
复制相似问题