submit data from PDF to WebService

1,762 views
Skip to first unread message

Gabriel

unread,
May 17, 2011, 5:46:57 PM5/17/11
to Adobe LiveCycle Developers
I understand we can get information from a webservice to a form, but
can i send data from a form to a webservice without pass through the
livecycle server?

rgs
Gabriel

Nithyanandam Dharmadass

unread,
May 18, 2011, 12:32:20 AM5/18/11
to live...@googlegroups.com
Yes, you can send part of the form or the complete form data to a Web Service.

var dataToSubmit = xfa.datasets.data.saveXML('pretty');

The above variable will hold the complete form data as String. You can post this to a web service and deserialize (String to XML) for processing.

Nith


--
You received this message because you are subscribed to the Google Groups "Adobe LiveCycle Developers" group.
To post to this group, send email to live...@googlegroups.com.
To unsubscribe from this group, send email to livecycle+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/livecycle?hl=en.




--
Regards,
Nith


---------------------------------------------------------------------------------------------------
The maximum strength of a chain is the strength of its' weakest link.
---------------------------------------------------------------------------------------------------

billy

unread,
May 18, 2011, 5:43:48 AM5/18/11
to Adobe LiveCycle Developers
You can do this either by data binding, or programaticaly.

To data bind, just right click on the data view tab and select new
connections. You can have many connections to webservices (unlike
schemas).


To do it programaticaly create a connection to the webservice;
var connection = Net.SOAP.connect(myUrl);

Now once you have this connection, you can call the methods of the
service using the dot notation;
var result = connection.myMethod({"paramenter1": dataToSubmit1,
"parameter2":dataToSubmit2});

It should be noted that you do need to reader extend your form for ppl
using Reader.


Billy

Hemant

unread,
May 18, 2011, 5:44:28 AM5/18/11
to Adobe LiveCycle Developers
Adding to Nith..

LiveCycle server is also not mandatory..
You can use IIS(or .asmx) or Apache Tomcat for that matter to deploy
the Application which can be consumed in PDF as WSDL..

Regards,
Hemant Garg

On May 18, 9:32 am, Nithyanandam Dharmadass <nith....@gmail.com>
wrote:
> Yes, you can send part of the form or the complete form data to a Web
> Service.
>
> var dataToSubmit = xfa.datasets.data.saveXML('pretty');
>
> The above variable will hold the complete form data as String. You can post
> this to a web service and deserialize (String to XML) for processing.
>
> *Nith*

tarekahf

unread,
Oct 27, 2012, 12:03:34 AM10/27/12
to live...@googlegroups.com

I am able to submit the entire PDF via HTTP to ASP.NET Request Object in .ASPX Web Page. On ASP.NET Web Page (ASPX), I am able to retrieve the submitted stream, and analyse it to extract the Data Fields and also the binary PDF File, and finally update SQL Server Database with the updated values from the PDF Fields, and save the PDF in Binary Format (to .PDF File) by converting the chunk element from Base64 String to Binary.

But this method, sometimes, it fails, and the entire submission fails (for various reasons such as IIS is down or SQL Server is Down or Validation Error on the server-side). The user in many cases gets frustrated, and I am blamed for this, because the user has lost all the Data Entry made. I am not sure why when the user press the BACK button on the browser, the PDF is reset to the beginning.

I think in order to avoid this, the best way is to submit to a Web Service, or simply call a Web Service and send the entire XDP to the Web Service. If something goes wrong, then at least the control is still on the client side, and the error can then be passed back to the user.

I hope someone can help with this.

How I can submit the entire PDF (XML Data + Binary Part) to a Web Service?

Tarek.

Hemant

unread,
Oct 27, 2012, 8:43:22 AM10/27/12
to live...@googlegroups.com
Hi Tarek,

Long back I faced the same issue and approached using web services to send the entire PDF.. 


For the use case, I have created a sample PDF and a web service. this wsdl is used in the PDF to send itself to the server.
PFA the sample PDF file where you can put the email address and by clicking the send button the same PDF will be sent to the server and then further sent to the mentioned email address in the PDF.
just a slight difference here with your requirement is that, you are trying to save the PDF file in database after receiving the binary PDF via web service but here I'm sending it to the mentioned email address.

The response is captured in the JavaScript console.
In the back-end i have used the asp.net web-service( .asmx).

Hope this helps...!!

Regards,
Hemant Garg 
SOapConnect.pdf
Message has been deleted

tarekahf

unread,
Oct 27, 2012, 2:46:44 PM10/27/12
to live...@googlegroups.com
Hi Hemant,
 
I tried to open the PDF in LiveCycle Designer, but it requires a password.
 
Tarek.

tarekahf

unread,
Oct 27, 2012, 3:46:21 PM10/27/12
to live...@googlegroups.com
Hemant, It is working! I have to know how you implemented this feature?

Tarek.

On Saturday, October 27, 2012 3:43:22 PM UTC+3, Hemant wrote:

Hemant

unread,
Oct 27, 2012, 9:04:23 PM10/27/12
to live...@googlegroups.com
Hi Tarek,

Since the PDF contains the server details and exact location of web service I had to encrypt the PDF.

I will let you know the functionality within the PDF.

I implemented following code in the button click event to send the PDF itself to the server.

//////
var service=SOAP.connect("http://domainName.com/webservice.asmx?wsdl");

var documentStream = Collab.documentToStream(event.target); 
var encodedStream = Net.streamEncode(documentStream, "base64"); 
var myBudget = util.stringFromStream(encodedStream, "utf-8");
var base64 = {soapType: "xsd:string",soapValue: myBudget}; 
var add = {soapType: "xsd:string",soapValue: email.rawValue}; 
var result = service.sendEmail({abc:base64, email:add});
for(var i in result ) console.println(i);
//////////

In the above code, "abc" and "email" are the input parameter names of the web service function named sendEmail(string abc, string email). so these names should be exact in the client code.

After posting this message i will break the existing sample code at the server,so the no more request are accepted from the sample PDF shared here.

I found this method to be the fastest, stable and simplest too to send PDF or any other binary data to the server. The same can also implemented for sending attachments from the PDF by adding JavaScript code to get the dataObjects.

Hope this helps..!!

Regards,
Hemant Garg

tarekahf

unread,
Oct 28, 2012, 1:37:11 AM10/28/12
to live...@googlegroups.com
Hemant,

Really thank you for posting the code details. It is pretty simple and easy.

Now, on the server side, I developed a comprehensive code library (using .NET APIs) to convert Base64 back to binary and save the PDF to File System, and perform the other validation ...etc.

Now this "Base64" generated by the sample you posted, if used at the server side, in the same manner, I should get same results, right?

I will give it a try during the next week, and will post back.

Tarek.

Hemant

unread,
Oct 28, 2012, 4:36:05 AM10/28/12
to live...@googlegroups.com
Interestingly it took me only three complete days to develop just 6 lines of code by reading the PDF JavaScript API reference documentation.  :)

Yes Tarek, on server side you need to convert Base64 string to ByteArray. 
ASP.Net provides direct APIs to do so..
Following is the sample C# code used in a web service to convert the base64 to byte array( in ASP.NET 3.5) and save it as binary file on the server location.
//////////////
[WebMethod]
public string sendEmail(string abc,string email) {  /// the "Base64" string received from the PDF
try {
     byte[] pdf = Convert.FromBase64String(abc);
     string SaveLocationPDF = Server.MapPath("~/serverlocation") + "\\" + "test.pdf";
     File.WriteAllBytes(SaveLocationPDF, pdf); // in case need to save the PDF in server folder location.
     ....
     ........
     ////// Here you can further add the code either to send an email or to the Database.
 }
 catch (Exception ex) {return(ex.ToString());}
}
//////////

Regards,
Hemant Garg

tarekahf

unread,
Oct 18, 2013, 8:11:09 AM10/18/13
to live...@googlegroups.com
Hi Hemant,

Sorry if this is a late reply... though I did not convert the submission yet to use Web Service, but I think I will have to do that soon, since we are planning to subcontract and hire a core programmer to implement various improvements to this subsystem.

Back to our subject....

I still think there is a small problem here. The last time I used "SOAP.Connect()" I am sure 100% that it will not work if the web service is implemented with Integrated Windows Authentication. This means, under IIS, it will force the client to identify himself by sending the authenticated User ID (in case of Windows), otherwise, it will prompt for Username and Password, but when I tried executing a Web Service using DataConnection it worked without any problem.

On the server side, I need to get the ID of the Authenticated User, which is required to perform Authorization. If Authorization fails, then the process must stop, and error is reported back (but the data entry must not be lost!).

Do you think I can executer a DataConnection Web Service instead of suing SOAP.Connect()?

Tarek.
Reply all
Reply to author
Forward
0 new messages