Rename based on If/Then/Else string Criteria
I grabbed some code on how to rename a file based on the string position within the file. That doesn't work for me because the data in the files changes so the text I need for renaming the file can be shifted. What I need instead is some sort of If/Then/Else formula.
I found that code here: https://forums.adobe.com/thread/2364649 but I'm trying to tweak it to suit my needs. I am incorporating this script into an Action in Acrobat that will run through a batch and rename (or create new files) in a designated folder.
This is the criteria I need for the rename:
IF the PDF contains the text "Packing List" THEN I need the new file name compiled by returning the value AFTER the string "Reference to Invoice" + "." + the value AFTER the string "Shipment Number" + "." + "pl" + ".pdf"
This would look something like this: 123456789.PPHB12345.pl.pdf
ELSE
I need the new file name compiled by returning the value AFTER the string ""Customs Invoice" + "." + the value AFTER the string "Shipment No." + "inv" +.pdf"
This would look something like this: 123456789.PPHB12345.inv.pdf
I'm new to javascript so need some assistance in how to write the code to do this.
var docRef = app.activeDocument;
var searchString = "Packing List";
var pronmbr = getPageNthWord(0,28,true) + "." + getPageNthWord(0,54,true) -this was part of of the original code from above and doesn't apply here.
var re = /\.pdf$/;
var fname = this.documentFileName.replace(re,"_");
var filename = pronmbr + "INV" + ".pdf";
Thank you for your help.
