A frequent question with Adobe Acrobat PDF forms is, "Can I submit the form back to itself?", or the variation, "Can I submit the PDF to another window?". The short answer is "No!". There is a longer answer, of course and you know I'm about to give it.
Acrobat supports JavaScript. Browsers support JavaScript. But Acrobat is not a Browser. JavaScript is a scripting language, and as such, acts upon the underlying Object Model. Think of it this way: JavaScript is a standardized way to talk to a system. But the underlying systems, in this case, are vastly different. This often confuses web developers who cannot understand why they can't get "window.open()" to work in a PDF. The answer is simple: Acrobat doesn't have a "window" object, let alone a "window.open()" method (and, no, "target" in a hyperlink doesn't work, either).
Let's restate the problem. In a web environment, the user browses to a PDF Form. You want them to fill out the form and submit it. You've set the PDF to submit to a web application (ASP.NET, ASP, PHP, whatever). The application processes the form data, and at that point you're finished. You really want the user's page to stay on the PDF. Perhaps, for example, they want to either 1) correct and resubmit the data or 2) submit ANOTHER record using the same form.
The problem is Acrobat. All you can do is submit the form, and the browser expects a response. The response has to be generated by your web application, and the browser is going to display that response. Submit the PDF Form and the browser navigates away from the PDF. As we've discussed, you cannot force the PDF to open a new window to display the results.
One solution is to have the web application redirect back to the original PDF. The exact mechanism will differ, depending on the server-side language you use. In PHP, for example, simply use the header function:
<?php
header('location:pdf_submit1.pdf');
?>
Go ahead, try it: pdf_submit1.pdf. A note here: I don't like this. As a user, when I submit a form I expect to SEE SOMETHING. This technique works, but the user is going to see the same PDF. How will they know their data was processed?
A better solution is to show the user that their data was submitted. This answers the question, "Can I submit a PDF Form to a new window?". No, but you can make the RESULTS page open a new window. The code below is a sample HTML response:
<html>
<head>
<script type="text/javascript">
self.location.href = "pdf_submit.pdf";
var respWin = window.open("","respWindow","height=150,width=250");
respWin.document.open();
respWin.document.write("<html><body
onBlur='self.focus();'><p>Thank you, your form was submitted!</p></body></html>");
respWin.document.close();
</script>
</body>
</html>
This response would be built by the web application. Your application would process all of the form results and output this code. The first thing the code does is navigate the main window back to the pdf, with the instruction self.location.href = "pdf_submit.pdf";. Next, use JavaScript to open a new window and write a custom response to the user. When the PDF loads in the main window, it will hide your popup window. To make sure the user sees the new window, we've added the onBlur='self.focus();' script in the child window's body tag.
See it run: pdf_submit.pdf.
A couple of things to note. Many popup blockers will consider the new window in the second solution to be a popup. You'll have to make your users aware, in your sign-in page, that they should allow popups for your site. Secondly, each of these solutions cause the PDF to be loaded TWICE. There is an extra "server round-trip". That's just the price you pay.
Robust data and form management applications can be developed around the Adobe Acrobat PDF Form technology. By combining HTTP, HTML and JavaScript navigation techniques, you can overcome some of the limitations in the Acrobat JavaScript model.
Thomas D. Greer has over 12 years experience in the printing business. He held the position of Director of Development for Consolidated Graphics, where he wrote the COIN eCommerce platform. Prior to that he was Vice-President of Technology of a large printing company acquired by Consolidated Graphics, where he was responsible for the development of a completely custom-written plant management system still in use.
Today Thomas provides consulting, development, implementation, and training services to commercial printers. He can be reached on the web at www.tgreer.com.
Perhaps you'd like to read some other technical articles I've written?
If you'd like to discuss this article, or make suggestions for future articles, join my free discussion forum.
My logo was designed by Rus Anderson, a skilled graphic artist with a wealth of experience in user interface and web design. I told Rus I wanted something simple and clean, that conveyed my expertise in document automation technologies. I also wanted an association with PostScript and PDF. I'm very pleased with the result. The "document icon" has become ubiquitous. It's obvious, when viewing the logo, that I'm involved in document production and automation. The red color is associated with Adobe, PostScript, and PDF. Overall, the effect is clean and memorable. Thanks, Rus!