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

Need help with dynamic PDF

Explorer ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

Hello Adobe Community,

Need some help on creating a dynamic test book. Please see image below.

The PDF will have a first page where the user will select which sections to include in the test book (at least one). Will do so by selecting the checkboxes and clicking the button "Generate Test Book".

The script will modify the PDF to only show pages corresponding to the selected section(s). Pages from not selected section(s) will be deleted from the test book.

I've been trying to figure out the best way to configure it.

  • I  created templates for each page in the document and hid them.
  • Since the user may have only Acrobat Reader, I'm trying to find a way to spawn the pages so they can also be deleted from Reader.
  • Need to add page number using fields so they are dynamic depending upon the selection.

So far, the problem I'm facing is that if  I delete a page, the associated template is also deleted. Is there a way to overcome this? Should I rethink the whole approach?

Any help is appreciated.

Capture01.png

 

 

TOPICS
JavaScript , PDF forms

Views

1.9K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Mar 01, 2023 Mar 01, 2023

"Pages from not selected section(s) will be deleted from the test book."

You should do the reverse: all pages templates hidden: user click: spawn the ticked pages only.

 

- Be sure to "spawn" the pages templates and not "show/hide", since Reader cannot show/hide them.

- A page spawned from a hidden template can be deleted by Reader (unlike "static" pages).

 

- Page numbers.

Place this as a Calculation script in a text field on static pages (so only the first page in this document):

event.value =

...

Votes

Translate

Translate
Community Expert ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

Hi @F.onsecaRig ,

 

You don't need to re-think the whole approach.

 

In fact I love this idea which I may employ in some of the  PDFs that I am working on.

 

If you're using a script you need to share it so the developer community can assist better and see what you could be missing.

 

Also keep in mind that, contrary  to the notion of counting pages starting with Page 1, the core JavaScript interpreter counts PDF elements (or objects) starting with zero (0).

 

That said, if you've employed hidden templates that will be spawned based off of the options given to your end-users in the "Generate Test Book" section, you may want to review how the deletion of spawned pages is interacting with what you currently declared in your script(s).

Votes

Translate

Translate

Report

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 ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

"Pages from not selected section(s) will be deleted from the test book."

You should do the reverse: all pages templates hidden: user click: spawn the ticked pages only.

 

- Be sure to "spawn" the pages templates and not "show/hide", since Reader cannot show/hide them.

- A page spawned from a hidden template can be deleted by Reader (unlike "static" pages).

 

- Page numbers.

Place this as a Calculation script in a text field on static pages (so only the first page in this document):

event.value = (event.target.page + 1) + " / " + this.numPages;

 

Place this as a Calculation script in a text field on pages templates (because the page number of a spawned page comes from an array, it's not a number):

event.value = (event.target.page[1] + 1) + " / " + this.numPages;

(Beware that the field will display an NaN error until the page is spawned)

 

Votes

Translate

Translate

Report

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
Explorer ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

Thanks @ls_rbls and @JR Boulay ,

This worked like a charm! Adding code below in case someone needs it.

 

// Creating the templates
var s = this.numPages - 1;
for ( var i = s; i > 0; i--){
  //console.println(i);
  var t = this.createTemplate({cName:"myTemplate0"+i, nPage:i });
  t.hidden = true;
}

// check status of three checkboxes
var s1 = this.getField("chkSection1");
var s2 = this.getField("chkSection2");
var s3 = this.getField("chkSection3");

if (s1.value == "Yes"){
  //Section 1 checked
  this.templates[0].spawn({nPage: this.numPages, bRename: false, bOverlay: false});
}

if (s2.value == "Yes"){
  //Section 2 checked
  this.templates[1].spawn({nPage: this.numPages, bRename: false, bOverlay: false});
}

if (s3.value == "Yes"){
  //Section 3 checked
  this.templates[2].spawn({nPage: this.numPages, bRename: false, bOverlay: false});
}

//Adds signature page
this.templates[3].spawn({nPage: this.numPages, bRename: false, bOverlay: false});
updatePageNum();

 

Now, just need to figure out how to make the actual TOC dynamic. Any ideas @JR Boulay ?

Happy customer, thank you!

Votes

Translate

Translate

Report

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 ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

What do you mean by "TOC dynamic"?

Acrobat Reader cannot create/delete bookmarks or change the name of thumbnails.

Votes

Translate

Translate

Report

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
Explorer ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

If only Section 1 is selected, then, TOC entries for Section 2 and Section 3 should not be part of the TOC. See below:

 

FonsecaRig_0-1677764225970.png

 

Votes

Translate

Translate

Report

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 ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

If I understand the question differently: when I create this type of document I delete everything and start again each time.
In other words, each click on a choice in the table of contents deletes all the pages spawned and respawn those that have been selected.
It makes things easier afterwards, for example you don't have to manage the position of the pages, and if the user changes his mind again, the fields of the deleted pages may come back already filled in.

Votes

Translate

Translate

Report

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
Explorer ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

Thanks! Can you see my reply above, regarding the TOC?

Votes

Translate

Translate

Report

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 ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

You should use show/hide fields.

Votes

Translate

Translate

Report

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
Explorer ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

LATEST

Thanks @JR Boulay , I ended up using show/hide fields with links on top of them to link to the bookmarks destinations.

Votes

Translate

Translate

Report

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