Reputation: 6736
Trying to auto-search with pdfjs, (and having hard time with the docs..)
THIS WORKS:
<input type="button" value="click-me" onclick="searchPDF('cpu');" />
THIS DOESN'T (jquery running ok)
$(document).ready(function() {
searchPDF('cpu');
});
HOW DO SUSPEND EXECUTION UNTIL THE PDF IS PARSED? (OR WHY ISN'T IT WORKING)
MODIFIED viewer.html (thanks to PDF.js - Using search function on embedded PDF )
// search with PDF.js
function searchPDF(td_text) {
//PDFView.findBar.open();
$('#findInput').val(td_text);
$("#tableDiv").focus();
PDFView.findBar.findNextButton.click();
var event = document.createEvent('CustomEvent');
event.initCustomEvent('find', true, true, {
query: td_text,
caseSensitive: $("#findMatchCase").prop('checked'),
highlightAll: $("#findHighlightAll").prop('checked'),
findPrevious: undefined
});
return event;
Upvotes: 1
Views: 2506
Reputation: 6736
Finally found a solution for us that doesn't digest javascript for breakfast:
(thanks to
Based on viewer.html and added jquery:
$(document).ready(function() {
document.addEventListener('textlayerrendered', function (e) {
if (e.detail.pageNumber === PDFView.page) {
// finished rendering, call a JS-function..
searchPDF('cpu');
}
}, true);
});
function searchPDF(str) {
alert('working');
..add code from
http://stackoverflow.com/questions/38976490/how-do-i-get-javascript-to-run-when-pdfjs-is-loaded
}
Upvotes: 1