Add total pages in a form field

New Here ,
Mar 21, 2021 Mar 21, 2021

Copy link to clipboard

Copied

Hi I would like to add the total pages into a form field as it can be variable. I can see that I could do this in a header but that is not the position wanted for this data on our form. Is their a short javascript that would add this and input it in a certain form field? Thanks

 

Sales5DC5_0-1616357754827.png

 

TOPICS
Edit and convert PDFs, JavaScript, PDF forms

Views

163

Likes

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
Most Valuable Participant ,
Mar 21, 2021 Mar 21, 2021

Copy link to clipboard

Copied

Yes, you can use this code to do it (as a doc-level script):

 

this.getField("pages").value = this.numPages;

Likes

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
New Here ,
Mar 21, 2021 Mar 21, 2021

Copy link to clipboard

Copied

Hi I don't get an error but also no figure is displayed in the field. Should I add anything else?

Sales5DC5_0-1616361431695.png

 

 

Likes

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
Most Valuable Participant ,
Mar 21, 2021 Mar 21, 2021

Copy link to clipboard

Copied

Remove the function definition.

Likes

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
New Here ,
Mar 21, 2021 Mar 21, 2021

Copy link to clipboard

Copied

I read a little more and found by combining your suggestion with another if I put this in calculate field box it worked:

 

event.value=this.numpages

Thanks for your help

Likes

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
Most Valuable Participant ,
Mar 21, 2021 Mar 21, 2021

Copy link to clipboard

Copied

First of all it's numPages, not numpages. Also, if you do it like that it won't update after you remove or add pages and then re-open the file...

Likes

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
New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

LATEST

Thanks in this case that is OK. I saw the typo but you can't edit posts unfortunately once added. I'm just posting this for me as a second point that to add a date this works:

 

event.value=util.printd("mm/d/yyyy", new Date());

Likes

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