getting response back from a Java Servlet to Drupal

by Deepak   Last Updated December 22, 2017 15:07 PM

My working scenario is like this, A webform (suppose an admission form for school) should be there on my drupal site and when a user clicks "submit" button a nicely formatted pdf file should be generated.

my approach is like this: 1. I have created a webform using webform module

  1. I have written a servlet to generate pdf file (currently hosted at another server)

  2. now I want to have communication between my servlet and drupal, so I created a small module that will execute custom function whenever user clicks submit button of the webform.

I am using curl to send the form data to servlet and it is working with http code 200.following is my code.

//my data actuly its coming from the webform
$fields = array(

$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);

I am getting the PDF file encoding printed in the browser. How can I force User to download it.

please guide me.

Tags : hooks webform

Answers 1

To force download, you want to set the proper headers for filename, content-disposition and content-length. In your case, it may need to be set from the Servlet application, but without knowing the details of $response, that's difficult to determine.

In general, though, your headers should look something like this:

'Content-disposition:attachment;filename=foobar.pdf' (content-disposition:inline is the opposite of this) 'Content-length:1234567098'

July 31, 2012 16:26 PM

Related Questions

webform: redirect to modified result page

Updated April 28, 2017 11:07 AM

webform "Load a pre-built option list" not shown

Updated February 25, 2016 03:03 AM