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

Submit and close the XFA form opened in Adobe Reader

neeraj.manayil
Registered: Feb 18 2009
Posts: 7
Answered

Hi,

I am using a XFA form in my application which users can edit and submit. If the user has unchecked the "Open PDF in browser" setting in Adobe Reader, the PDF opens in Adobe Reader. I would like to close the PDF or Adobe Reader when the user submit the PDF by clicking the Submit button provided.

I also want to show the resultant HTML page on a browser after submitting the PDF. I am able to do this, but if I use event.target.closeDoc() in button click event I am not getting the result page even though the PDF submission worked fine.

Any suggestions?

Any help will be highly appreciated.

Thanks
Neeraj

My Product Information:
Reader 9.3, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You can use the "doc.external" property (event.target.external for an XFA form) to detect when the PDF is displayed in a browser.

Instead of closing the PDF, have you tried using the "app.launchURL()" function?


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

neeraj.manayil
Registered: Feb 18 2009
Posts: 7
Thanks for your suggestion. Using the "app.LaunchURL()" function will not fully resolve my issue fully.

I would like to close the PDF so that it is no more visible to the user.

Apart from this the resultant page depends upon the PDF submission (The resultant page can be displayed only after the successful PDF submission). So calling app.LaunchURL() just after the form submission will not work for me since the form submission might not be over by that time.

Is it possible to know whether the submssion got completed?
Can we retrieve any response?
Is it possible to call "app.LaunchURL()" function after a time delay?

I tried the following code with postSubmit event to delay the launch of result page by 5 seconds.

if (event.target.external == false)
{
app.setTimeOut("app.launchURL("result.php")",5000);
event.target.closeDoc();
}

Please let me know if I am doing something wrong here.

I hope this will resolve my complete problems.

Thanks once again
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There are couple of options. If the URL of the submission has the same domain as the URL to the PDF then you can send back an FDF response. Which can contain code to launch the url and close the PDF. I've often used this method to give the user a response in a popup alert.

If you do have cross domain issues then you can place a script in the validate or format event of a hidden text field. Have the response data place a value in this field that triggers the launch URL and close action.


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

neeraj.manayil
Registered: Feb 18 2009
Posts: 7
I am submitting the PDF to the same domain. But I am submitting the PDF using HTTP form submit not by sending the XML.

Can I send a FDF Response for a Http form Submision?
If yes, do you have some sample code for this?

Can I refresh the browser which opened the PDF in Adobe Reader after submitting the PDF?

Currently the result page is getting displayed in the last browser instance opened on the machine. Is there a window.opener object available to identify the opener browser and show the result page in the same browser.

Thank you very much for your quick response. I hope I am very near for a solution.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The PDF itself (or really the Acrobat/Reader Object) doesn't have any direct control over the browser environment, or much of an awareness of it. Acrobat knows it's being displayed in an external environment, and under special circumstances it has a communication channel to that environment. But it doesn't know it's specifically in a browser.

I haven't experimented much with forcing browser windows open or closed from Acrobat so I don't know the limits. All you can do is see what happens when you force a new page to open and close the PDF. I've heard reports that the new HTML page from app.launchURL replaces the PDF. However, I think this is browser and OS dependent. It's awfully hard to control directly without a hard channel of communication between the two.

Now, about the data submission. All PDF data submissions to an URL are implemented with an HTTP Post/Get Request. I imagine you're using a CGI script of some sort to process the data? These types of scripts typically return HTML, but for a PDF you can return one of the PDF data formats instead. The CGI script has to set the "content-type" field in the header to the appropriate value and fill in the response body with the correctly formatted data. This can be done in virtually all CGI and server side languages (I've done this at one time or another in all of them). You'll find some examples on this forum if you search for terms like "PHP" and "CGI".


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

kathleensundby
Registered: Jan 27 2011
Posts: 1
I am using Adobe Acrobat X Pro. I have a submit button. I would like to be able to submit the form. Instead of it ending there, I want to redirect to a payment URL. However, when I hit the submit button, it ends up at the email site. When manually closing the email, it then redirects to the URL of the payment page. How can I redirect to the payment page without having to manually close the email site?

kathleen