Skip to main content
first.officer
Inspiring
October 7, 2020
Answered

JavaScript to submit specified page in multiple page document

  • October 7, 2020
  • 3 replies
  • 2077 views

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....

 

 

This topic has been closed for replies.
Correct answer try67

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);

 

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
October 7, 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);

 

first.officer
Inspiring
October 7, 2020

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.

 

 

JR Boulay
Community Expert
Community Expert
October 7, 2020

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. 😉

Acrobate du PDF, InDesigner et Photoshopographe
Thom Parker
Community Expert
Community Expert
October 7, 2020

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
first.officer
Inspiring
October 7, 2020

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.

Thom Parker
Community Expert
Community Expert
October 7, 2020

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 PDFScriptingUse the Acrobat JavaScript Reference early and often