Skip to main content
GatsbyNZ
Known Participant
October 28, 2022
Question

Need Help with PDF Javascript for

  • October 28, 2022
  • 1 reply
  • 1066 views

Hi Guys, just do a post to see if anyone can help me with non-programmer. 

I am creating an interactive pdf form and I used page 7 (11 pages in total) as a template for spawning extra"Task Card" for engineering purposes. I created a button for page generating on the Template page, and I also created a text field on the template page that can populate the sequential numbers for each new Task Card created (the Template page text field will have the total number of cards generated +1), which means the text field on the template page will have the number 7 if I generate the Task Card six times.

  • Here is the barrier I am facing, on the second page of this PDF, I have an index table with a column named Task Card No., so how am I able to let the Task Card number (not the sum total number) pop into each cell every time I generate a card, which is basically a sequential number 1, 2, 3, etc...
  • Another barrier is on the Template page, there is another text field with some brief description of a job and another corresponding column on the index table on the second page, and how am I able to come up with a script to let the job description populate into the corresponding column of the index table on the 2nd page for every new Card generated. (we fill in the Card first)

 

Here is the script I used for Template page button for spawning page and generate sequential number in the text field:

this.getTemplate("Task Card").
spawn(this.numPages-2,true,false);
var f = this.getField("task no 1");
f.value = Number(f.value)+1;
f.defaultValue = f.value;

Really appreciate it if anyone can help me out...:)

Thanks a million!

Regards,

This topic has been closed for replies.

1 reply

BarlaeDC
Community Expert
Community Expert
October 28, 2022

Hi,

 

Can you share the document so that we can work from the same starting point, makes sure we actually solve your problem?

GatsbyNZ
GatsbyNZAuthor
Known Participant
October 28, 2022

Hi Barlae, thanks for responding, here is the PDF attached, 

  1. On the 4th page of this PDF (Job Control Sheet), there is an Index table (Task Cards), the 1st column of which needs to reflect the sequential number of the Task Card generated each time based on the template already created  (Page 7) , alternatively, the sequential number can match field value of "Task No." on the Task Card created each time. (not sure whether I've made it clear enough:) )
  2. The 3rd column of this table (Brief Description of Discrepancy) needs to correspond to the text field named "Task" (task 1 of its field name) on the generated Task Card. This means whatever "task" is written there on the Task Card will populate the corresponding field on that Task Cards table on page 4.
  3. To spawn the template page, I used this.getTemplate("Task Card").
    spawn(this.numPages-2,true,false); to make sure the newly generated page will be placed after the page generated previously, but I don't know how to script that correctly except using numPages minus 2, and I am sure there is a better way of scripting it.

I cannot thank you enough for it!

Really appreciate it.

 

Regards,

BarlaeDC
Community Expert
Community Expert
November 8, 2022

Hi,

 

I have taken a look at the file, and have a couple of questions.

 

1. Why do we spawn the task above the page that we clicked on? Can this be moved to page 4 ( so we only have 1 button doing the spawning)

 

2. Are the numbers of the tasks always sequential, every form will go 1, 2,3, 4,5 .........?