Copy link to clipboard
Copied
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
});
}
}
}
Copy link to clipboard
Copied
By the way. When I run the debugger I get this:
TypeError: pageText.includes is not a function
7:Console:Exec
undefined
Copy link to clipboard
Copied
Correct, it's not, at least not one that is supported in Acrobat. You can use indexOf, instead. However, that won't work, either, since getPageNthWord returns a single word, not the full text of the page, so you can't compare what it returns to a whole phrase.
You would need to either check the phrase one word at a time, or to first extract the full page text, save it as a single string, and then search it.
Copy link to clipboard
Copied
I take it you are the one offering E-Learning from PDFAutomationStation.com. If so, does your course teach this kind stuff? Or this something we have to think outside the box?
Copy link to clipboard
Copied
No, that's not my website, but @PDF Automation Station 's.
I offer a complete solution for your needs, if you're interested.
Copy link to clipboard
Copied
My (paid for) course will not teach you this, specifically. It will teach you how to read, write, test, and apply JavaScript for Acrobat Pro, and how to quickly find solutions in the reference guide. The complete course outline is available in the Course Outline tab here. If you are interested, message me privately and I will provide a discount code for you.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now