Changes

Jump to navigation Jump to search
2,783 bytes added ,  22:23, 4 February 2009
→‎The code: inserting js code because it's not allowed as an upload.
=== The code ===
The following two attached javascript files are to be placed in the Acrobat javascripts folder, e.g. C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Javascripts, and then Acrobat is restarted. '''<code>add-hyphen-menu.js </code>''' adds a menu item for "Highlight Hyphens..." on the Tools menu. <pre>// Add a menu item for "Highlight Hyphens" app.addMenuItem({ cName: "Highlight Hyphens...", cParent: "Tools", cExec: "highlightHyphens()"});</pre> '''<code>findAndAnnot.js </code>''' defines the function that finds line-broken words and highlights the first "quad" of each.<pre>// Find and highlight all words that are line-broken with "-"// Lars Huttar, lars_huttar@sil.org, 2009-02-04 function highlightHyphens() { console.show(); // show console, for debugging. console.println('entered highlightFinalHyphens()');  var word, numWords, q; var count = 0; var startTime = (new Date()).getTime(); var startPage = 0; // may want to specify page range var hyphThisPage;  for (var i = startPage; i < this.numPages; i++) { hyphThisPage = 0; numWords = this.getPageNumWords(i); for (var j = 0; j < numWords; j++) { word = this.getPageNthWord(i, j, false); // don't strip punctuation! // console.println('word ' + j + ': ' + word); // was: if (word.charAt(word.length - 1) == '-') { // Don't highlight single hyphens (which are common in headers/footers) // and which tend to come in as "- "; // Also, words that are line-broken with hyphens (tend to?) come in as // a single word with medial hyphen, e.g. "vari-eties", whereas those that // have a non-breaking hyphen come in as multiple words, e.g. "day-" "to-" "day". // So don't highlight words whose only hyphen is at the end. // We don't expect any word breaks with one character before the hyphen, e.g. "C-ontinent", // but if there were any we'd want to know about it! if ((word.length > 2 || (word.length > 1 && word.charAt(0) != '-'))) { ind = word.indexOf('-'); if (ind > 0 && ind < word.length - 1) { hyphThisPage++; console.println('page ' + (i+1) + '/' + this.numPages + ' word: ' + word); q = this.getPageNthWordQuads(i, j); // The following call throws an exception in Reader; we don't have the right to manipulate comments, // unless such has been enabled on this PDF using LiveCycle. this.addAnnot({page: i, type: "Highlight", quads: new Array(q[0]) }); // highlight only the first quad } } } console.println('page ' + (i+1) + '/' + this.numPages + ': ' + hyphThisPage + ' hyphens'); } var nPages = this.numPages - startPage; var endTime = (new Date()).getTime(); console.println('Completed ' + nPages + ' pages in ' + ((endTime - startTime)/1000.0).toFixed(2) + ' sec. (' + ((nPages + 0.0) * 1000 / (endTime - startTime)).toFixed(2) + ' pages/sec)');}</pre>
53

edits

Navigation menu