Help with excel import and delete pages script
Hello. I'll try to make it as simple as possible. I have some data from excel (saved as tab-delimited) that I need to import into a 5 page PDF. I am using the script below to import, and it works very well. All the fields import and saves individual PDF's (one for each record). However, I need to expand that functionality by deleting certain pages before it saves the document by looking at different checkboxes. Code below is what I use to import the records.
// specify the filename of the data file
var fileName = "/Users/MacMike/Desktop/Test.txt"; // the tab delimited text file containing the data
var outputDir = "/Users/MacMike/Desktop/Dump/"; // make sure this ends with a '/'
var err = 0;
var idx = 0;
while (err == 0) {
err = this.importTextData(fileName, idx); // imports the next record
if (err == -1)
app.alert("Error: Cannot Open File");
else if (err == -2)
app.alert("Error: Cannot Load Data");
else if (err == 1)
app.alert("Warning: Missing Data");
else if (err == 2)
app.alert("Warning: User Cancelled Row Select");
else if (err == 3)
app.alert("Warning: User Cancelled File Select");
else if (err == 0) {
this.saveAs(outputDir + this.getField("Full Name (First Last)").value + "-" + this.getField("Event Title").value + ".pdf"); // saves the file
idx++;
}
}
As I mentioned before importing works amazingly well.
My PDF consists of 5 pages (p0=registration-info, p1=Dir-contract, p2=ndarp-trademark agreement, p3=oyb-contract, p4=oyb-trademark agreement). My idea is that upon importing the data, the script will look at some checkboxes and determine which contracts to delete out of the PDF and then save it. I wrote out the syntax of what I think it should look like. I am not a programmer, and know just a little. I looked through the documentation and this is what I came up with. I just don't know how to combine it to work. Below is code I came up with.
var dir = this.getField("Associate Director"); // checkbox
var aldir = this.getField("Alumni Director"); // checkbox
var fac = this.getField("Facilitator"); // checkbox
var alfac = this.getField("Alumni Facilitator"); // checkbox
var oyb = this.getField("Optimize Your Brain"); //checkbox
var poyb = this.getField("DVD and Workbook Previously Purchased"); // checkbox
// Below are all the possible training options.
if (dir.value=="Checked" || aldir.value=="" || fac.value=="" || alfac.value=="" || oyb.value=="" || poyb.value=="") {
this.deletePages({nStart:3, nEnd:4})
}
else if (dir.value=="" || aldir.value=="Checked" || fac.value=="" || alfac.value=="" || oyb.value=="" || poyb.value=="") {
this.deletePages({nStart:3, nEnd:4})
}
else if (dir.value=="" || aldir.value=="" || fac.value=="Checked" || alfac.value=="" || oyb.value=="" || poyb.value=="") {
this.deletePages({nStart:2, nEnd:4})
}
else if (dir.value=="" || aldir.value=="" || fac.value=="" || alfac.value=="Checked" || oyb.value=="" || poyb.value=="") {
this.deletePages({nStart:2, nEnd:4})
}
else if (dir.value=="" || aldir.value=="" || fac.value=="Checked" || alfac.value=="" || oyb.value=="Checked" || poyb.value=="") {
this.deletePages({nStart:2, nEnd:2})
}
else if (dir.value=="" || aldir.value=="" || fac.value=="" || alfac.value=="Checked" || oyb.value=="Checked" || poyb.value=="") {
this.deletePages({nStart:2, nEnd:2})
}
else if (dir.value=="" || aldir.value=="" || fac.value=="Checked" || alfac.value=="" || oyb.value=="" || poyb.value=="Checked") {
this.deletePages({nStart:2, nEnd:2})
}
else if (dir.value=="" || aldir.value=="" || fac.value=="" || alfac.value=="Checked" || oyb.value=="" || poyb.value=="Checked") {
this.deletePages({nStart:2, nEnd:2})
}
else if (dir.value=="Checked" || aldir.value=="" || fac.value=="" || alfac.value=="" || oyb.value=="Checked" || poyb.value=="") {
this.deletePages(none) // I realize this is incorrect. Just showing that this option results in no deleted pages.
}
else if (dir.value=="" || aldir.value=="Checked" || fac.value=="" || alfac.value=="" || oyb.value=="Checked" || poyb.value=="") {
this.deletePages(none) // I realize this is incorrect. Just showing that this option results in no deleted pages.
}
else if (dir.value=="Checked" || aldir.value=="" || fac.value=="" || alfac.value=="" || oyb.value=="" || poyb.value=="Checked") {
this.deletePages(none) // I realize this is incorrect. Just showing that this option results in no deleted pages.
}
else if (dir.value=="" || aldir.value=="Checked" || fac.value=="" || alfac.value=="" || oyb.value=="" || poyb.value=="Checked") {
this.deletePages(none) // I realize this is incorrect. Just showing that this option results in no deleted pages.
}
else if (dir.value=="" || aldir.value=="" || fac.value=="" || alfac.value=="" || oyb.value=="Checked" || poyb.value=="") {
this.deletePages({nStart:1, nEnd:2})
}
else (dir.value=="" || aldir.value=="" || fac.value=="" || alfac.value=="" || oyb.value=="" || poyb.value=="Checked") {
this.deletePages({nStart:1, nEnd:2})
}
How do I combine these two so that I can create a temp document import my data, check the status of checkboxes and delete the appropriate pages and save the file then go to the next record? I have the first part done. It imports great, and saves right, but I don't know what to do next. Thanks for any help!
Or is there another way to do this?
Michael
