In Adobe Acrobat Pro DC can I have a print button select certain pages?
I'm trying to get a print button to check if the state is VA, CA or UT, if so then check if the checkbox named disclosures is checked off, if not then error pops up, if checked then check for which pages to print. Can I do this in my version of adobe? if so what is wrong with the following script?
// Get the values of the fields
var fieldValue = this.getField("Business Address_State 1").value;
var companyAValue = this.getField("Existing Cash Advance CompanyA").value;
var companyBValue = this.getField("Existing Cash Advance CompanyB").value;
var checkboxValue = this.getField("Disclosures").value;
// Check if the checkbox value is 'No' when the state is VA, CA, or UT
if ((fieldValue === "VA" || fieldValue === "CA" || fieldValue === "UT") && checkboxValue === "No") {
// Display an error message
app.alert("You cannot print until the disclosures are sent and signed, and the checkbox is checked.");
} else {
// Determine the pages to print based on the conditions
var pagesToPrint = [];
if (companyAValue && companyBValue) {
if (fieldValue === "VA") {
pagesToPrint = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23];
} else {
pagesToPrint = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,23];
}
} else if (companyAValue && !companyBValue) {
if (fieldValue === "VA") {
pagesToPrint = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23];
} else {
pagesToPrint = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,23];
}
} else if (!companyAValue && fieldValue === "VA") {
pagesToPrint = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,22,23];
} else if (!companyAValue && fieldValue !== "VA") {
pagesToPrint = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,23];
}
// Print the specified pages
if (pagesToPrint.length > 0) {
var printParams = {
bUI: true,
bSilent: false,
bShrinkToFit: true,
nStart: pagesToPrint[0] - 1,
nEnd: pagesToPrint[pagesToPrint.length - 1] - 1,
aAllPages: pagesToPrint.map(function(page) { return page - 1; }) // adjust page indices to be 0-based
};
this.print(printParams);
} else {
// Display an error message
app.alert("You cannot print until the disclosures are sent and signed, and the checkbox is checked.");
}
}
