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

JavaScript to submit specified page in multiple page document

Engaged ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Hi all,

 

I have the following script in a button object, that populates a chosen drop-down menu item export value, as the destination email address;

 

var email = this.getField("Dropdown").value;
this.mailDoc(false, email);

 

The above woks fine - but this page resides in a multiple page document, and am wondering if there is a way of making it attach the page in question only, to the email that is then sent adapting the script as shown (or similar)?.

 

The script above sends back the whole PDF, without flattening the form page, and is exactly what is desired.

 

Thanks....

 

 

TOPICS
PDF forms

Views

1.2K

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 , Oct 07, 2020 Oct 07, 2020

It is possible to do it from a doc-level (or field-level) script, actually, but it won't work in the free Reader, only in Acrobat.

Here's the basic code to submit just the first page of a file:

 

 

var newDoc = this.extractPages(0,0);
newDoc.mailDoc({cTo: "me@server.com"});
newDoc.closeDoc(true);

 

Votes

Translate

Translate
Community Expert ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Extracting or emailing single pages cannot be done from a document script. The general solution for this is to make the single page an attachment to the PDF, then transfer data to the attachment and email it.  Flattening also cannot be done from a script in a PDF. But you can make the fields on the attachment readonly. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Engaged ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Hi Thom,

 

Thanks for the reply - I don't actually want to flatten (the form) at all, so the script is great that I have thus far, in as much as it does exactly what i want by way of attaching the full PDF to the email message, and allowing the recipient user to edit and use the form at the receiving end.

 

The query was really as to how to go about having the button only send that one single page from amongst the other pages in the document, but put the relevant script (if it exists or ispossible? sounds likely not from what you've written above) within the existing script shown (which resides in the 'Mouse Up' - Run a javascript). The script isn't at a document level.

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

By "Document Script" I meant a script in the PDF file, not just "Document Level". So, if you look at the "doc.extractPages()" function in the Acrobat JavaScript Reference, you'll see that it doesn't work in Reader and has privilege restrictions. As Try67 points out, it is possible to do this if the PDF is viewed in Acrobat Professional. That's a pretty narrow usage model. 

 

So back to my original statement. If you want to send a single page, then do this. Extract the page to a separate PDF file. Attach it to the original document. Then write your email script to open the attachment, transfer data from main form to the opened attachment, the email the attachment.   

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Classic answer is no: because deleting pages (before sendind by email) requiresAcrobat Pro or Acrobat Standard, Acrobat Reader cannot.

 

My answer is may be: if you can be sure that end users will use Adobe Reader XI or Acrobat Reader DC, I can explain how to convert "unwanted" pages as templates, how to spawn these pages and how to delete them with Acrobat Reader (DC or XI only) by adding a few lines to your script.

 

Acrobat Reader DC/XI cannot delete "normal" pages but it can delete spawned pages. 😉

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

It is possible to do it from a doc-level (or field-level) script, actually, but it won't work in the free Reader, only in Acrobat.

Here's the basic code to submit just the first page of a file:

 

 

var newDoc = this.extractPages(0,0);
newDoc.mailDoc({cTo: "me@server.com"});
newDoc.closeDoc(true);

 

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
Engaged ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Thanks for the replies all,

 

And the form will be used using Adobe DC Pro - which I also have and use, so shouldnt be any issue there.

 

 

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
Engaged ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Hi try67,

 

That code works nicely! many thanks for that - but is there a way of making the email address dynamic, in as much as it changes the email address dependent upon a selection the user makes from a drop-down field?. I've managed to achieve it in the earlier code I posted earlier, but can't seem to incorporate it in to what you have authored...

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
Engaged ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Actually......managed it in the end;

 

var newDoc = this.extractPages(2,3);
var email = this.getField("Dropdown").value;
newDoc.mailDoc(false, email);
newDoc.closeDoc(true);

 

Probably not entirely correct...but it works lol.

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

LATEST

Here's an article on how to dynamically setup email parameters:

https://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address/

 

And here's one about lists with an example that selects email addresses from a list.

https://acrobatusers.com/tutorials/list_and_combo_in_lc/

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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