크롬 확장 프로그램을 개발 중입니다. 내가 알고 싶은 것은 팝업이 pdf에서 텍스트를 표시 할 수 있다는 것입니다. popup.html는 다음과 같이 표시됩니다크롬 확장 프로그램에서 PDF에서 텍스트를 추출
{
"name": "englishhelper",
"version": "0.0.1",
"description": "",
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"background":{
"script":["background.js","PDF.js"]
},
"browser_action":{
"default_icon":"icon_png",
"default_popup":"popup.html"
},
"manifest_version": 2
}
:
‘use strict’;
var pdf = PDFJS.getDocument('http://www.pacer.gov/documents/pacermanual.pdf');
var pdf = PDFJS.getDocument('pacermanual.pdf');
pdf.then(function(pdf) {
var maxPages = pdf.pdfInfo.numPages;
for (var j = 1; j <= maxPages; j++) {
var page = pdf.getPage(j);
// the callback function - we create one per page
var processPageText = function processPageText(pageIndex) {
return function(pageData, content) {
return function(text) {
// bidiTexts has a property identifying whether this
// text is left-to-right or right-to-left
for (var i = 0; i < text.bidiTexts.length; i++) {
str += text.bidiTexts[i].str;
}
if (pageData.pageInfo.pageIndex ===
maxPages - 1) {
// later this will insert into an index
console.log(str);
}
}
}
}(j);
var processPage = function processPage(pageData) {
var content = pageData.getTextContent();
content.then(processPageText(pageData, content));
}
page.then(processPage);
}
});
매니페스트는 다음과 같습니다 : 나는 PDF.js를 검색 및 테스트에 크롬 확장 backgroud.js에 다음 코드를 작성했다 따르십시오 :
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="popup.css">
<title></title>
</head>
<body>
<script src="background.js"></script>
<script src="PDF.js"></script>
</body>
</html>
콘솔에 "PDFJS가 정의되지 않았습니다"가 표시됩니다. "PDF.js"는 popup.html에 포함되어 있습니다. 크롬 확장에서 PDF.js를 사용할 수 있습니까?
코드에서 예를 들어, HTML에서
<script>
태그의 순서에 적용되는 배경 페이지에 아직 도서관은 거기에 포함되지 않습니다. 너는 무엇을 기대 하느냐? – Xan나는 분명히 설명하지 못해 죄송합니다. "PDF.js"가 다운로드되어 popup.html을 @Xan –
과 같이 추가합니다. 이름에도 불구하고 팝업에서도 실행되는'background.js'입니까? 그렇지 않은 경우, 두 개의 별도 컨텍스트입니다. 무엇보다도 질문에 대한 매니페스트를 포함하십시오. – Xan