These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Calculations not working after page is spawned

Stagea
Registered: Jul 1 2010
Posts: 4
Answered

I am incredibly new to this and I don't really know what I am asking but here goes...

I'm trying to create an invoice in Acrobat Pro for my business where I can spawn new pages from a template, each new page being a new invoice.

When I spawn a new page, the field names change as I had intended, however the calculations don't work because the field names have been changed and my javaScript refers to the original field names on the template. They work fine on my template of course. Am I trying to do the impossible?

My Product Information:
Acrobat Pro 9.3.1, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The spawned field names change in a regular and predictable way. Your code has to take this into account and generate new field names in the calculation script. Here's a clue, the name of the current field, the one the calculation script is inside of, has the same prefix as all the other fields on the page. All the code needs to do is capture this prefix and use it to create the names for the other fields.

Look at this article:
http://www.acrobatusers.com/tutorials/2006/string_splitting

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Stagea
Registered: Jul 1 2010
Posts: 4
Unfortunately, I think this is way beyond my capabilities at the moment! At least now I know what I need to do. Thanks for helping me out.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Maybe a look at [url=http://www.planetpdf.com/developer/article.asp?ContentID=a_lesson_in_templates_for_adob&gid=6466]A Lesson in Templates for Adobe Acrobat[/url] by Dave Wright might help you understand what and how to rename and use renamed fields created by a template. You should have the fields that are renamed when a template is spawned on the first page prefixed with 'P0.' for page 1 and any field's value you want copied on the spawned pages do not provide a name prefix.

George Kaiser

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Good one George! Haven't heard from Dave in years, but he sure knows his stuff. He wrote that article 6 years ago and it's still right on the mark. The good stuff in Acrobat hasn't changed, Thank Heavens!! And lets keep our fingers crossed that it doesn't.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Stagea
Registered: Jul 1 2010
Posts: 4
Thanks gkaiseril, I found that article when I first started this form and it's been very helpful but unfortunately, the spawn new page from template script in the article seems to only work if you don't have any fields involved in calculations.

Basically, I need to make an invoice file so when I click "New Invoice", a new page appears which is completely independent of the other pages in the document. I don't need any information to carry over from previous pages as each new invoice is for a new customer or new job (I would like the form to be numbered but I can't even figure THIS thing out!). I am able to get the pages to spawn and they are completely independent of the other pages but the calculations don't work. I'll try changing the names of the fields in the script to the prefix I have chosen but I don't think it will work because they change every time a new page is spawned.

Thanks for your help.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You have to add some code to the calculations to obtain the page number. Each field has a name and Java Script can provide that field name. Since each field has a hierarchical naming structure with a dot separating the levels of the name, one can even extract the individual levels of the name. So if you can obtain the page reference for a field, you can then use that value to build the string for each needed field name used in a calculation.

[url=http://www.planetpdf.com/developer/article.asp?ContentID=javascript_binding_a_variabl&gid=6259]JavaScript - Binding a variable to the field on a page[/url]I have uploaded a PDf package with the the form and a working template to [url=https://acrobat.com/#d=8dYRFaFgvDkMPMWQZAdFIw]Sample Template Package[/url]. The code has comments and I used some functions.

George Kaiser