Import Data from tab-delimited text file and update Document Properties
I am working on an automation involving multiple PDFs placed in a foler. Using ActionWizard and Execute JavaScript option, I am trying to update the metadata like subject and Keywords from spreadsheet.
Spreadsheet is converted to Tab-delimited text file.
Column A Column B Column C
PDF_Name Subject Keywords
PDF1 Subject1 Keywords1
PDF2 Subject2 Keywords2
.....
I want the code to Compare the PDF name with column A and update the same PDF subject and keywords respective to the same row.
I have built the below code so far but i am not sure where is the mistake. When i run the code, nothing happends. Please help.
// Get the current PDF file name
var currentPDFName = this.document.fileName;
// Path to the tab-delimited data file
var dataFilePath = "/path/to/your/tab-delimited/data.txt";
var dataFile = util.readFileIntoStream(dataFilePath);
// Read the data file and update information
var line;
while ((line = util.readLine(dataFile)) !== null) {
var values = line.split('\t');
var pdfName = values[0];
var subject = values[1];
var keywords = values[2];
if (pdfName === currentPDFName) {
this.info.Subject = subject;
this.info.Keywords = keywords;
break; // Assuming each PDF name is unique in the data
}
}
dataFile.close();
