gpt4 book ai didi

javascript - PDFJS 查找并导航至页面

转载 作者:行者123 更新时间:2023-11-28 03:43:00 32 4
gpt4 key购买 nike

我们正在使用 PDFJS 突出显示/查找 PDF 文件中的文本。效果很好。另一个功能是导航到特定页面。我们正在尝试设置 PdfApplicationViewer 的 CurrentPage 属性。但它会抛出错误,例如

parentOffset not set. Cannot Scroll

附上下面的js代码。

 'use strict';

if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
alert('Please build the pdfjs-dist library using\n' + ' `gulp dist-install`');
}

// The workerSrc property shall be specified.
//
PDFJS.workerSrc = 'lib/pdfviewer/pdf.worker.js';

// Some PDFs need external cmaps.
//
// PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/';
// PDFJS.cMapPacked = true;

var DEFAULT_URL = PdfUrl;
var SEARCH_FOR = SearchWord; // try 'Mozilla';

var container = document.getElementById('viewerContainer');

// (Optionally) enable hyperlinks within PDF files.
var pdfLinkService = new PDFJS.PDFLinkService();

var pdfViewer = new PDFJS.PDFViewer({
container: container,
linkService: pdfLinkService,
});

pdfLinkService.setViewer(pdfViewer);

// (Optionally) enable find controller.
var pdfFindController = new PDFJS.PDFFindController({
pdfViewer: pdfViewer
});
pdfViewer.setFindController(pdfFindController);

container.addEventListener('pagesinit', function () {
// We can use pdfViewer now, e.g. let's change default scale.
pdfViewer.currentScaleValue = 'page-width';
if (SEARCH_FOR) { // We can try search for things
pdfFindController.executeCommand('find', {
caseSensitive: false,
findPrevious: undefined,
highlightAll: true,
phraseSearch: true,
query: SEARCH_FOR,

});
}
});

// Loading document.
PDFJS.getDocument(DEFAULT_URL).then(function (pdfDocument) {
// Document loaded, specifying document for the viewer and
// the (optional) linkService.
pdfViewer.setDocument(pdfDocument);
pdfLinkService.setDocument(pdfDocument, null);
PDFViewerApplication.page = parseInt(SearchPageNo);

});

最佳答案

设法使用 setCurrenPage 选项修复

关于javascript - PDFJS 查找并导航至页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48768491/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com