Copy link to clipboard
Copied
Hello,
I'm working on a form for safety reviews. When filling it in, the user is supposed to declare all safety events first.
I have a set of 2 pages that I would like to duplicate for each safety event (1 safety event = 2 analysis pages). In a nutshell, the total number of pages of my form depends on the number of safety events declared.
All my safety events are declared in text fields (1 filled text field = 1 safety event).
I would like, if it is at all possible (but I'm confident it is) to have, each time a safety event text field is filled, my 2 analysis pages to be duplicated so that, in the end, I have 2 analysis pages per safety event.
I hope I'm being clear here, don't hesitate to ask questions.
I just started to study how PDF Forms work with JavaScript, so it would be nice to have so help. I struggle to find the variables I can use to do this : I imagine ther must be some kind of variable for each page that I could duplicate...? But I don't know if it's that simple.
I'm gonna keep on looking, in the meantime, I thank you for your precious help.
Copy link to clipboard
Copied
To do that you would need to convert your pages into Template objects and then you'll be able to spawn new copies from them, using a script. This is a complex task, though.
Copy link to clipboard
Copied
Ok, I'm gonna do some research on that.
I'll let you know what I find.
Copy link to clipboard
Copied
Hello again,
I succeeded, a quick view on how.
I put my 2 analysis pages in a separated file (insert.pdf).
In my main file, I ask the user to fill in the safety events and then to click on a button that inserts the safety analysis pages (using insertPages function) for each safety event. This is quite tricky because the insertPages function has to be ran in a priviledged environment so I had to go through a Folder-Level javascript.
Then, after inserting the 2 pages, it creates the fields to be filled in (because I don't want all the analysis fields to come from my insert.pdf file otherwise they will all show the same data). The function for that task is addField.
I can send some code if needed.