Copy link to clipboard
Copied
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.");
}
}
Copy link to clipboard
Copied
in the future, to find the best place to post your message, use the list here, https://community.adobe.com/
p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post if it helps you get responses.
<moved from using the community>
Copy link to clipboard
Copied
Is it possible to hide pages in Adobe Acrobat Pro DC?
Copy link to clipboard
Copied
Yes. Convert them to Template objects and you'll be able to hide them. Note that you won't be able to "un-hide" them if the file is used in Reader, though. You will be able to spawn copies from them, though.
Copy link to clipboard
Copied
What's wrong with the script is that you're defining a whole array of page numbers, but then only use the first and last values from it in your code, so it will print the whole range between those two pages, no matter what else is in the array. You need to split your array to sub-arrays of continues page ranges.
For example, instead of this:
pagesToPrint = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,23];
It should be:
pagesToPrint = [[2,18], [23,23]];
But you would have to use the PrintParams object and specify this 2D-array (after reducing one from each page number) as its printRange property for it to work, or do it in separate print commands. Read the documentation of the print method and the PrintParams object for more details.
Copy link to clipboard
Copied
Thanks for your reply,
I have modified my script to the following:
// 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 the checkbox is checked.");
} else {
// Determine the page range based on the conditions
var pagesToPrint = this.getPrintParams();
if (companyAValue && companyBValue) {
if (fieldValue === "VA") {
pagesToPrint = [1, 22];
} else {
pagesToPrint = [[1, 19], [22, 22]];
}
} else if (companyAValue && !companyBValue) {
if (fieldValue === "VA") {
pagesToPrint = [[1, 18], [20, 22]];
} else {
pagesToPrint = [[1, 18], [22, 22]];
}
} else if (!companyAValue && fieldValue === "VA") {
pagesToPrint = [[1, 17], [20, 22]];
} else {
pagesToPrint = [[1, 17], [22, 22]];
}
// 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 the checkbox is checked.");
}
}
It will only print a range of pages 1-22 for a VA with company A and B that have value. It is not following the rule of the error pop up when the checkbox is not checked and it does not respond for any other conditions.
Copy link to clipboard
Copied
The PrintParams object is not set up correctly. You need to read the documentation of how to use it, and what properties it has.
Copy link to clipboard
Copied
The following was the script for the just the error pop up, before adding the other contions that works. I changed it, and not sure which way is better.
// Get the value of the field and the checkbox
var fieldValue = this.getField("Business Address_State 1").value;
var checkboxValue = this.getField("Disclosures").value;
// Check if the field is not CA, VA, or UT, or if the field is CA, VA, or UT and the checkbox is checked
if (fieldValue !== "CA" && fieldValue !== "VA" && fieldValue !== "UT" || (fieldValue === "CA" || fieldValue === "VA" || fieldValue === "UT") && checkboxValue === "Yes") {
// Print the document
this.print({bUI: true, bSilent: false, bShrinkToFit: true});
} else {
// Display an error message
app.alert("You cannot print until the dislosures are sent and signed and the checkbox is checked.");
}
Copy link to clipboard
Copied
I've explained what needs to be done. Have you read the documentation of the PrintParams object, and looked at the examples of the print method?