Insert two PDFs after a page when it finds a keyword
Hi, I have JS that will not work for me. My goal here is insert two PDFs after it find a page with the keyword "Please make checks payable to:". I can do it for a single PDF and add to the last page. The issue here is I can have two or more page with that keyword. I.E. A single PDF with hundreds of pages. the first instance the keyword could be found on page 3. So this is when I would like to add the two PDF then the next instance would be page 5. so this is when would like to add the same two PDFs. And this process would continue until it no long find the keyword. The problem here is all the files are downloaded as one PDF instead of single PDFs. This is my code:
// Define the two PDFs to be inserted
var pdf1 = "C:/Users/MyName/Desktop/Billing Test/letterhead.pdf";
var pdf2 = "C:/Users/MyName/Desktop/Billing Test/RATE - FY 25.pdf";
// Function to insert PDFs after pages with specific text
function insertPDFsAfterText() {
var numPages = this.numPages;
for (var i = numPages - 1; i >= 0; i--) {
var pageText = this.getPageNthWord(i, 0, true);
if (pageText.includes ('Please make checks payable to:')) {
this.insertPages({
nPage: i + 1,
cPath: pdf1
});
this.insertPages({
nPage: i + 2,
cPath: pdf2
});
}
}
}
