Skip to main content
Known Participant
May 17, 2023
Question

In Adobe Acrobat Pro DC can I have a print button select certain pages?

  • May 17, 2023
  • 3 replies
  • 2366 views

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.");
}
}

This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
May 18, 2023

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.

Known Participant
May 18, 2023

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.

 

try67
Community Expert
Community Expert
May 18, 2023

The PrintParams object is not set up correctly. You need to read the documentation of how to use it, and what properties it has.

Known Participant
May 18, 2023

Is it possible to hide pages in Adobe Acrobat Pro DC? 

try67
Community Expert
Community Expert
May 18, 2023

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.

kglad
Community Expert
Community Expert
May 17, 2023

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>