[go: up one dir, main page]

0% found this document useful (0 votes)
9 views2 pages

P&id Javascript

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

P&id Javascript

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

function highlightWordsAndExportToCSV() {

var nTotal = 0;
var highlightedText00 = []; // Array to store highlighted text containing "00"
var keywordsWith00 = ["CL", "CP", "CM", "CT"];
var exactKeywords = ["TT", "PT", "FT", "LT"];

for (var p = 0; p < this.numPages; p++) {


var cnt = this.getPageNumWords(p);
for (var w = 0; w < cnt; w++) {
var s = this.getPageNthWord(p, w);

// Ensure s is defined and is a string


if (s && typeof s === 'string') {
// Check for words starting with '00' and containing specified
keywords
if (s.length > 1 && s.charAt(0) === '2' && s.charAt(1) === '1') {
for (var i = 0; i < keywordsWith00.length; i++) {
if (s.indexOf(keywordsWith00[i]) !== -1) {
this.addAnnot({
page: p,
type: "Highlight",
quads: this.getPageNthWordQuads(p, w),
color: ["0", "0", "0.5"] // Dark Blue color (RGB)
});
highlightedText00.push(s); // Store highlighted text
containing "00"
nTotal++;
break; // Break to avoid multiple highlights for the
same word
}
}
}

// Check for exact matches with specified keywords


for (var j = 0; j < exactKeywords.length; j++) {
if (s === exactKeywords[j]) {
this.addAnnot({
page: p,
type: "Highlight",
quads: this.getPageNthWordQuads(p, w),
color: ["0", "0", "0.5"] // Dark Blue color (RGB)
});
nTotal++;
break; // Break after highlighting to avoid duplicates
}
}
}
}
}

// Prepare CSV content


var csvContent = "Highlighted Text\n"; // Header for the CSV
highlightedText00.forEach(function(text) {
csvContent += text + "\n"; // Add each highlighted text as a new line
});

console.println("Total highlighted: " + nTotal);


console.println("Highlighted Text containing '00': " +
highlightedText00.join(", "));
// Provide instructions to save the CSV content
console.println("To export the highlighted text to a CSV file, copy the
following content:\n");
console.println(csvContent);

return { totalHighlighted: nTotal, highlightedText00: highlightedText00 }; //


Return both results
}

// Execute the highlighting function


var result = highlightWordsAndExportToCSV();

You might also like