Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hide unhide fileds and/or pages in form with three states.

Contributor ,
Apr 12, 2023 Apr 12, 2023

After a long search on the Internet, I found an approach to build my project on it.

 

 

if (event.value == 5) {
getField("A").display = display.visible;
getField("B").display = display.visible;
getField("C").display = display.visible;
} else {
getField("A").display = display.hidden;
getField("B").display = display.hidden;
getField("B").display = display.hidden;
}

 

File is this link
Working with Adobe Acrobat 2020 Pro.

Found this script at www.acronaut.de and would like to expand it to adapt it to my project.

Would like to extend this script approach so that:
Drop-down menu consists of three states.
Each state opens and closes other fields.
At the same time, the fields should each move up or down when the upper fields above them fade in or out.
Is this possible? if so, how can I incorporate this into the existing script?
Is it possible to show/hide the pages at the same time and not print them out if they are not needed or have no fields that you can hide?

 

...could it be possible to hide the pages that are not needed in each form with the drop down selection instead of programming each field individually? if yes how?

 

I hope I expressed myself correctly and made it clear.

 

Any help is welcome.

 

Thanks in advance!

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF forms
6.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2023 Apr 12, 2023

To 'hide' pages, make them into a template and then spawn them when needed.

To move field, you would need to get field coordinates using 'rect' (this can be rather complex for beginner).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 12, 2023 Apr 12, 2023

Many thanks for the quick response.

I have some additional questions :-).


You write: To 'hide' pages, make them into a template and then spawn them when needed.

 

Can you guide me how to do this, step by step instructions? ...would be beneficial for a beginner like me :-).

 

You write: To move field, you would need to get field coordinates using 'rect' (this can be rather complex for beginner).

 

I've already tried, I've also expanded the code a bit...

if (event.value == 5) {
	getField("A").display = display.visible;
	getField("B").display = display.visible;
this.getField("C").rect= [274, 659, 527, 632];
} else {
	getField("A").display = display.hidden;
	getField("B").display = display.hidden;
this.getField("C").rect= [274, 787, 527, 760];
}

...and seen that this can be very but very tedious and can be afflicted with many errors, especially if a beginner like me tries to do it.

That's why at the end there was the question of whether I can hide and show entire pages (shouldn't be printed out if they are hide) depending on the dropdown selection.

 

Thank you for your time and patience

Niko

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2023 Apr 12, 2023

To create a template from a page, select 'Organize Pages' tool, click on page you wish to make into a template, then on toolbar click on 'More' then 'Page Templates', give template a name (for example "temp1"), click on 'Add' and uncheck checkbox next to template name.

Now to spawn template use something like this:

var t1 = this.getTemplate("temp1");
if (event.value == 1)
t1.spawn({nPage: numPages, bRename: false, bOverlay: false});

You can change where template spawn by changing 'nPage:' and you can set 'bRename:' to 'true' if you wish fields to be renamed when spawned (otherwise leave as false).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 13, 2023 Apr 13, 2023

I tried it according to your specifications (as far as my understanding goes) and show it, but I'm doing something wrong.
Here my attempt:

var t1 = this.getTemplate("temp1");
if (event.value == 1)
t1.spawn({nPage: numPages, bRename: false, bOverlay: false});
var t1 = this.getTemplate("temp1");
if (event.value == 5)
t1.spawn({nPage: numPages, bRename: false, bOverlay: false});

I want to make sure that when I select "5" everything is back in the initial state ("1"), unfortunately I can't do it. 😞
At the same time, the question arises for me, if I want to show and show three different pages in any combination between the pages, many selection variants would be required (more than three).

Maybe a tip how I could manage these variants with three options in the script? 🙂
...or I've just made a mistake in thinking 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2023 Apr 13, 2023

You don't need to call var t1 for each condition, one time is enough.

If you want to set to initial state, you will need to add condition to delete page you added because template cannot be hidden.

At the same time, the question arises for me, if I want to show and show three different pages in any combination between the pages, many selection variants would be required (more than three).

Not sure if I understand what you want to do here?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 13, 2023 Apr 13, 2023

As a beginner, it's difficult to articulate exactly what you're trying to achieve, sorry for that :-(.


I want the following:

In a PDF file with 3 pages, I only want page 1&3 or page 2&3 or page 1&2 or all 3 pages to be displayed via a dropdown.

So that I can switch from one state to the other with a dropdown.

How can you change your script to do this?

 

Thanks for your help and support so far, appreciate it very much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2023 Apr 13, 2023

Is your dropdown on one of those pages?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 13, 2023 Apr 13, 2023

Yes...if possible in all constellations it should be possible to select the dropdown pages :-).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2023 Apr 13, 2023

I don't think it's possible to make all pages into templates like that, you would need at least one page that isn't a template and from there manipulate other pages, I may be wrong but for me first template always disappear.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 14, 2023 Apr 14, 2023

So there's nothing possible?

Is there a nutritional possibility in this direction?

..even if a page would add an additional page that is not a template? ...if yes how?

I would be very happy about a solution proposal (also approximate) and step-by-step instructions with the script :-).

I would like to thank you for your patience and understanding so far.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 14, 2023 Apr 14, 2023

It's possible with templates, but at least have one page that is not a template.

Can you describe your workflow, and what are you actually trying to achieve?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 14, 2023 Apr 14, 2023

That's not true. You can set all pages as Templates, but you can't hide them all. There must be at least one visible page at all times.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 14, 2023 Apr 14, 2023

Thanks for the info. That would be great! 🙂

What I want to do (correction with 4 pages): In a PDF file with 4 pages,

I want only page 2&3, or page 3&4, or page 2&4, via a dropdown selection,

the first page will always be visible.

So basically, I can switch from one state to the other with the drop down selection.

...would it be possible to get such a code to include in the data validation of the drop down menu?

It would be really great if I could get such a template together.

Would also help me a lot for more forms 🙂.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 14, 2023 Apr 14, 2023

Yes, if you don't change page 1 you can make other pages in template and spawn them depending on dropdown choice on page 1.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 14, 2023 Apr 14, 2023

I don't know if I'm making myself clear enough!

Unfortunately, I'm not very fluent in the English language.

Is it possible to get a script? so that I can use this as a template?

A script that meets all the requirements and not just for one page.

 

Thx.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 14, 2023 Apr 14, 2023

Not likely, maybe if someone is in a good mood, but mostly people here will help you to make your script to work, not to give you a script.

Although, you can contact one of the experts privately and try to hire them to do the job for you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 15, 2023 Apr 15, 2023

After a long time back and forth in this forum, I was in despair for a moment.

No one could give a specific solution.

Thought it was up to me that I'm too stupid to understand.

But I asked the same question in my AI and oh wonder... the solution was very simple.

I wonder why life is made so difficult for a beginner here.

Why should I pay extra for a simple suggested solution?

Am I not paying enough to purchase the software?

It is not a commissioned work, just a script template, as you can get in bulk for free in any office software.

At the end of the day, one can ask oneself, what kind of justification for the existence of such a forum can there be?

I am almost certain that such settings will not last long in the new AI age.

Anyway thanks to everyone involved for joining this conversation and posting the walkthrough with steps how to do it if anyone else needs it too.

 

Here is an example of how you can create a script to show or hide pages based on a drop-down menu selection in Adobe Acrobat Pro 2020:

  1. Create the drop-down field and name it “Dropdown”.
  2. Add the options for the drop-down field: “A”, “B”, “C”, and “ABC”.
  3. Select ‘A’ as the initial option of the drop-down field using the following script in the console: this.getField ("Dropdown").value = "A";
  4. Hide “temp2”, “temp3”, and “temp4” using the following scripts in the console:

this.getTemplate("temp2").hidden = true;

this.getTemplate("temp3").hidden = true;

this.getTemplate("temp4").hidden = true;

5. Add a custom validation script to the drop-down field that shows or hides specific pages or templates based on the selected option:

 

var v = event.value;
if (v == "A") {
    this.getTemplate("temp2").hidden = false;
    this.getTemplate("temp3").hidden = false;
    this.getTemplate("temp4").hidden = true;
} else if (v == "B") {
    this.getTemplate("temp2").hidden = false;
    this.getTemplate("temp3").hidden = true;
    this.getTemplate("temp4").hidden = false;
} else if (v == "C") {
    this.getTemplate("temp2").hidden = true;
    this.getTemplate("temp3").hidden = false;
    this.getTemplate("temp4").hidden = false;
} else if (v == "ABC") {
    this.getTemplate("temp2").hidden = false;
    this.getTemplate("temp3").hidden = false;
    this.getTemplate("temp4").hidden = false;
}

 

This script will show or hide specific pages or templates based on the selected option from the drop-down menu. You can modify the script to fit your specific needs.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2023 Apr 15, 2023

If you are to share this file with someone else, you should know that this will not work in Acrobat Reader.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 17, 2023 Apr 17, 2023
LATEST

I know that, that's my next task, how I can accomplish this.

That's why I'll open a new question, maybe there's someone who can give me help there.

 

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 13, 2023 Apr 13, 2023

A note on moving fields around (for example to close up a gap). We don't like to say things are impossible, when there is a way, but this is not just hard for beginners. It is very hard for expecienced programmers too. And nobody does it, pretty much. It isn't also really a solution to making dynamic forms, because you can only move fields in the current page, and any serious application would want to be able to close up things over several pages. It's best to just say "no that can't be done" and move on. The only dyanmic control you really have is to use template pages. But beware - these won't work in web browsers or email or on mobile devices -- if you can't control where your form is to be used, best to give up on that too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 13, 2023 Apr 13, 2023

Thanks for the tip, that's why I'm trying to hide and show different pages in a PDF file (as well as not print when hidden).

I have received wonderful support from Ms. Nesa Nurani so far and I hope that I am not intrusive, as I need more information than beginners can do this.


In a PDF file with 3 pages, I would like to have only page 1&3 or page 2&3, or page 1&2 displayed via dropdown. How can the existing script be changed in order to be able to accomplish this?

 

Thanks again and any help is welcome 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines