Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Using Adobe LiveCycle Designer with ASP.NET to populate PDF Forms from Server Database.

Avatar

Level 8

[Thread Edited By Adobe]

/*Don’t forget to meet and greet your fellow peers virtually by telling them about yourself here

Go ahead and to it now: https://adobe.ly/3eDnB4v */

 

Actual Question:

With Google, I did a very very long search on how to use Adobe LiveCycle Designer to design Interactive/Dynamic Forms, and publish them to the IIS Server and use ASP.NET to populate such forms with field values from back-end Database such as SQL Server.



We are designing and implementing Electronic Forms ASP.NET Application that must detect the user currently logged in to the Windows Intranet (under IIS), and should perform a Look-up to the Back-End Database to extract the User Related Data and Populate the Form Fields to start the Form Processing.



We have the following facts:

1. The forms will be designed using Adobe LiveCycle Designer 7.1.



2. We will NOT use Adobe LiveCycle Forms since it is not on our budget yet.



3. The users will have the required Adobe Acrobat version on the Client PC.



In a typical scenario, the user would go through these steps:



1. The user logs on to the Intranet using his Windows Login ID and Password. Then he starts the APS.NET Application for Forms Processing.



2. He will request a form to fill. The form may be populated with sensitive information such as Salary and only the requesting user must be able to see his Salary on any form.



3. On the server side, the system will use the User Windows ID to perform a query against the Back-End Database and generate the required XML Data.



4. The system must then link/merge the generated XML Data with the requested form and render (post) the form back to the user for further printing and/or submitting via email.



That's it !



I found an add-in product "Adobe LiveCycle® Designer add-in for Microsoft Visual Studio .NET" but it only wraps XPD forms in Visual Studio Component which is not of a great help to my requirements.



If any one could give me any hint on how to implement such requirements.



I truly appreciate any help.



Tarek.

275 Replies

Avatar

Level 8

Hi gurlnpink ,

Appreciate your update. I might use iTextSharp in my next project.

As per my research about 2 years ago, I figured out that iTextSharp was desinged to handle Acrobat PDF not XFA Forms. I thought at that time that it will not be easy for example to populate a XFA form with repeating subform in a Dynamic PDF. I am not 100% sure though.

I appreciate it if you let me know if you can use iTextSharp to populate and read from a repeating Subform in a Dynamic XFA PDF.

Tarek.

Avatar

Level 2

Hi Tarek,

     I have only used iTextSharp to populate textfields and manipulate the visibility of buttons inside a PDF.  You can populate any objects inside a PDF as long as you assign a definite name per object.  This is as far as I have used the dll.  It actually took me awhile to understand how to use it as there aren't a lot of help on the web

Goodluck on your new challenge

Avatar

Former Community Member

Hi Tarek,

We have an ASP.NET 3.5 application that is serving PDFs and works perfectly in IE 6 but has some bad behavior in IE 7.

We are using Forms Authentication, cookies, session variables, and Master pages. Our application is running in IIS on Server 2003. The application is used in our intranet only so we control all the workstations. All are XP SP2. Some have IE 6, some have IE 7.  Reader is version 9.3.3 on all PCs.

Our PDFs were created using LiveCycle Designer 8.2 and we are using LiveCycle Reader Extension Server to enable the docs. All our docs have signatures using Topaz signature pads and a button that saves the document to a network server then submits data back to the ASP.NET app using JavaScript: submitForm. Enabled PDFs are stored in subdirectory of the application on the web server.

The user can select documents and navigate through the set of documents, signing and saving. Each document is loaded in an iframe on our navigation page. The iframe src is set to an aspx page that creates XDP containing data to fill in the PDF and uses

Response.Clear()

Response.ContentType = "application/vnd.adobe.xdp+xml"

Response.Write(string containing valid XDP)

   Response.End()

As I said, IE 6 is fine, but in IE 7: some time after the first document but not on any particular document, a PDF will “bust out” of the iFrame and take over the application window, losing the ability to navigate through the remaining documents.

Here are some ideas we had about what might be causing it but did not find any resolution

  • some setting in IE 7 or Reader or IIS
  • file associations
  • having acrobat and reader and/or multiple version of reader on a PC: we tried on a PC that only had Reader 9.3.3, same bad behavior
  • PDF files are in the same domain so the “cross-domain” security issue should not be a factor

These are some settings were tried:

-          Internet Options -> Security -> Custom Level -> Check the Enable(not secure) radio button for "Launching programs and files in an IFRAME"

-          Internet Options -> Security -> Custom Level -> Check the Enable(not secure) radio button for "Navigate sub-frames across different domains"

-          Internet Options -> Advanced -> Check the option "Empty Temporary Internet Files folder when browser is closed"

-          Tools -> Manage Add-ons -> Disabled and Enabled the Adobe PDF Link Helper.

-          In Adobe - Edit -> Preferences -> Internet -> Unchecked "Allow Fast Web View"

-          In Adobe - Edit -> Preferences -> Internet -> Unchecked "Allow speculative downloading in the background"

Any ideas would be greatly appreciated!

Thanks…

Avatar

Level 8

Hi JimboWx,

Actually, it is not easy to predict the cause of the prolem you are

facing, but I will try to help. I never tried using IFRAME for rendering

PDF (XDP) using response.write(), beucase I know this is not a

recommended way, besides, I understand that IFRAME is also not a

recommended approach in general. I used IFRAME, OBJECT or EMBED tags (if

I remember correctly) to render a PDF using a direct link to the PDF,

and they all worked successfully.

Try any combination of the following:

1. In the ASPX Page which is rendering the XDP, make sure it does not

have any HTML Markup in the BODY section. Comment out all markups. Then,

remove the command "response.clear()" from the code-behined. Make sure

nothing is rendered before the command "response.ContentType=...",

2. Try using a direct link to a PDF not to ASPX Page. If this works,

then the problem is most likely from "response.clear()".

3. Check the complete documentation of IFRAME and try to find a way to

tweak its behaviour.

4. Try using OBJECT or EMBED tags instead of IFRAME. Try using a Direct

Link to PDF and also a link to the same ASPX page.

5. Try with FireFox and IE8. This could be a nasty IE7 bug.

I hope my suggestions will be of help to you.

Tarek.

Avatar

Former Community Member

Hi Tarek,

Thank you for your quick response. 

We tried your suggestions:

1. In the ASPX Page which is rendering the XDP, make sure it does not have any HTML Markup in the BODY section. Comment out all markups. Then, remove the command "response.clear()" from the code-behind. Make sure nothing is rendered before the command "response.ContentType=...",

            ~ No change in behavior

           

2. Try using a direct link to a PDF not to ASPX Page. If this works, then the problem is most likely from "response.clear()".

   ~Direct to PDF: Fixes bad behavior SEE ADDITIONAL COMMENTS BELOW

3. Check the complete documentation of IFRAME and try to find a way to tweak its behaviour.

      ~ Tried various things to no avail.

4. Try using OBJECT or EMBED tags instead of IFRAME. Try using a Direct Link to PDF and also a link to the same ASPX page.

      ~ Tried EMBED tag, caused an ERROR in html source:

                  Validation (XHTML 1.0 Transitional): Element ‘embed’ is not supported.

   ~ Tried OBJECT tag.

    1. Aspx – always takes over parent window in both IE6 and IE7
    2. Direct to PDF – PDF loads in object, page that submitForm submits to takes over parent window.

5. Try with FireFox and IE8. This could be a nasty IE7 bug.

      ~ Not an option at this time:

a.       Firefox:  we only use IE

b.       IE8: One of our third party apps isn’t compatible

Here are my new questions:

1. Can we push data into PDF without XDP and server up the PDF instead of the XDP? I know it can be done with LC Form Server, but that is not in our budget.

2. In your response you said:

“I never tried using IFRAME for rendering PDF (XDP) using response.write(), beucase I know this is not a recommended way, besides, I understand that IFRAME is also not a recommended approach in general.”

Other than IFRAME, OBJECT, and EMBED, is there another way to embed a PDF in a page? We don’t want to pop a window or replace our navigation window as the user will have multiple PDFs to sign and save.

3. How can we be 100% sure that there is no additional markup in our page?

Here is the html side of the page. This was the barest .Net would let us make the html without causing an error.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="OurPage.aspx.vb" Inherits="OurDocApp.OurPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head runat="server">

    <title></title>

</head>

<body>

</body>

</html>

Thanks again for your help.

Avatar

Level 8

Hi JimboWx,

You must have spent a lot of effort on this. I can only imagine

different way trying to help.

Try the following:

1. Use IFRAME Nested Inside IFRAME, ie, IFRAM1 points to IFRAME2 which

points to the ASPX Page rendering the PDF,

2. Use IFRAME pointing to HTML/ASPX Page which is EMBEDing or using

OBJECT Tag to ASPX page rendering the PDF.

3. Using IFRAME according to its documented functions, should not cause

the problem you are reporting. So, try in FireFox or IE8 just to see if

the behaviour is the same or not.

Tarek.

Avatar

Former Community Member

Hi Tarek,

Once we saw that a PDF worked perfectly, it seemed to us like the XDP wrapper was causing our issue.

We decided to try a server function since we have LiveCycle Reader Extension Server… we weren’t sure what functionality we would get since we only purchased LRES but it was worth a try! After looking over the Quick Starts from Adobe, we found one that suited our needs and were able to call the importData function of Form Data Integration Service. This function takes in two byte arrays: the template PDF and the XDP data and returns a new PDF with the data embedded in it. The functionality of the Signatures (Topaz) and the Reader Extenstions remain intact.

In case anyone else wants to explore, here is the link to “Programming with LiveCycle ES2”

http://help.adobe.com/en_US/livecycle/9.0/programLC/help/index.htm

Under “API Quick Starts (Code Examples)”

            “Form Data Integration Service API Quick Starts”

                        “Invoking LiveCycle ES2 using MTOM” – explains how to add a Service Reference to your ASP.Net project: http://help.adobe.com/en_US/livecycle/9.0/programLC/help/index.htm?content=000532.html#1857175

                        “Quick Start (MTOM): Importing form data using the web service API” - explains how to call importData: http://help.adobe.com/en_US/livecycle/9.0/programLC/help/index.htm?content=000204.html#1560289

Two basic steps:

Add a Service Reference to you ASP.NET project (must be Microsoft Visual Studio 2008)

  1. In the Project menu, select Add Service Reference.
  2. In the Address dialog box, specify the WSDL to the LiveCycle ES2 service:

http://YOURSERVERNAME:8080/soap/services/FormDataIntegration?WSDL&lc_version=9.0.1

  1. Click Go
  2. Name your service, we used FormDataIntegrationService
  3. Click OK.

This step adds a section to your web.config: <system.serviceModel>

Add code to the page that is loaded in the IFRAME:

'fill ds with data to push into template PDF

Dim ds As New DataSet

' wrap in XML

Dim xml As New StringBuilder

With xml

       .Append("<?xml version=""1.0"" encoding=""UTF-8""?>")

       .Append("<xfa:datasets xmlns:xfa=""http://www.xfa.org/schema/xfa-data/1.0/"">")

       .Append("<xfa:data>")

       .Append(ds.GetXml)

       .Append("</xfa:data>")

       .Append("</xfa:datasets>")

End With

' read XML into byte array

Dim bXML As Byte() = System.Text.Encoding.ASCII.GetBytes(xml.ToString)

' read template PDF into byte array

Dim bPDF() As Byte = File.ReadAllBytes("STRING CONTAINING VALID PATH & FILE NAME")

' Create Client

Dim dataClient As New FormDataIntegrationService.FormDataIntegrationClient

' Important: the endpoint address must have ?blob=mtom to be able to access the MTOM objects

‘ we plan on using the web.config entry for address & concat ?blob=mtom so we can change servers in the future.

dataClient.Endpoint.Address = New System.ServiceModel.EndpointAddress( _       "http://YOURSERVERNAME:8080/soap/services/FormDataIntegration?blob=mtom")

' Enable BASIC HTTP authentication

Dim b As ServiceModel.BasicHttpBinding = CType(dataClient.Endpoint.Binding, ServiceModel.BasicHttpBinding)

b.MessageEncoding = ServiceModel.WSMessageEncoding.Mtom

dataClient.ClientCredentials.UserName.UserName = "YOURUSERNAME"

dataClient.ClientCredentials.UserName.Password = "YOURPASSWORD"

b.Security.Transport.ClientCredentialType = ServiceModel.HttpClientCredentialType.Basic

b.Security.Mode = ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly

b.MaxReceivedMessageSize = 2000000

b.MaxBufferSize = 2000000

b.ReaderQuotas.MaxArrayLength = 2000000

' read template PDF byte array into BLOB

Dim inPDF As New FormDataIntegrationService.BLOB

inPDF.MTOM = bPDF

' read data byte array into BLOB

Dim inData As New FormDataIntegrationService.BLOB

inData.MTOM = bXML

' call importData and get back BLOB

Dim outPDF As New FormDataIntegrationService.BLOB

outPDF = dataClient.importData(inPDF, inData)

' set up response type

Response.ContentType = "application/pdf"

' get byte array from MTOM

Response.BinaryWrite(outPDF.MTOM)

' end reponse

Response.End()

Thank you so much for your time.

Avatar

Level 8

Hi JimboWx,

I am really happy you found the solution to the problem. I hope my input was helpful.

It never occurred to my mind that if you have Adobe LiveCycle Reader Extensions Server then you can generate PDF by merging Template with XDP Data. I though that LRES is only to reader enable PDFs, but you can Generate PDFs ? No licensing issues here ?

The result of your work is so valuable to me.

Thank you so much for your feedback.

Tarek.

Avatar

Level 2

HI Tarek,

My XML is like below when I export the form data,

<?xml version="1.0" encoding="UTF-8" ?>

<fields>

  <Patient_First_Name>AnandBabu</Patient_First_Name>

</fields>

I have written the below C# code in a custom HTTP handler to render the PDF with prepopulated data in a iFrame

StringBuilder xmlData = new StringBuilder();

                xmlData.Append("<?xml version='1.0' encoding='UTF-8'?>");

                xmlData.Append("<?xfa generator='AdobeDesigner_V8.2'?>");

                xmlData.Append("<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>");

                xmlData.Append("<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>");

                xmlData.Append("<xfa:data>");

                xmlData.Append("<fields>");

                xmlData.Append("<Patient_First_Name>Jack</Patient_First_Name>");

                xmlData.Append("</fields>");

                xmlData.Append("</xfa:datasets>");

                xmlData.Append("<pdf href='http://localhost:52229/Documents/c1dcff54-ce62-4aa1-96f0-bd416f469cf9.pdf' xmlns='http://ns.adobe.com/xdp/pdf/'/>");

                xmlData.Append("</xdp:xdp>");

context.Response.ContentType = "application/vnd.adobe.xdp+xml";

                context.Response.Write(xmlData.ToString());

When I run the code, am getting the below adobe reader error message in my web page "There was an error opening this document. This file cannot be found"

Am I doing anything incorrect?

Please throw some light on this.




I

I



Avatar

Former Community Member

Make sure the path is correct...

ALSO NOTE:

If you are using VISUAL STUDIO for debugging, click on the pdf (http://localhost:52229/Documents/c1dcff54-ce62-4aa1-96f0-bd416f469cf9. pdf) in solution explorer, and set the build action property in the properties window to "content", and set the property copy to output directory to "Always".

Recompile, and viola!

Avatar

Level 2

No, I'm still getting the same error. I double checked that the pdf link is working fine and the property is set as you have suggested.

Avatar

Former Community Member

You didn't post your whole code, so I'm assuming you did these in the order in which they appear below..

Response.Clear()

Response.ContentType=".."

Response.Write(...)

Response.End()

Also, make sure you restart your ASP.net debugger by closing your solution & VS, this will copy the PDF.

Avatar

Level 2

I did that but no help. Missed to mention that my form is Acrobat PDF form and not livecycle form. is this the correct approach to populate data automatically in acrobat form?

Avatar

Former Community Member

For Acro-forms, you need to use FDF, or XFDF.

Avatar

Level 2

Do you have any sample to merge xfdf with acro form?

I'm trying this now,

string uniqueFileName = Guid.NewGuid().ToString();

                string newFile = HttpContext.Current.Server.MapPath(string.Format("~/Documents/{0}.pdf", uniqueFileName));

                File.WriteAllBytes(newFile, document);

StringBuilder xmlData = new StringBuilder();

                xmlData.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

                xmlData.Append("<xfdf xmlns='http://ns.adobe.com/xfdf/' xml:space=\"preserve\">");

                xmlData.Append(string.Format("<f href='http://localhost:52229/Documents/{0}.pdf'/>", uniqueFileName));

                xmlData.Append("<fields>");

                xmlData.Append("<field name=\"First_Name\"><value>Jack</value></field>");

                xmlData.Append("<field name=\"Last_Name\"><value>Shephered</value></field>");

                xmlData.Append("</fields>");

                xmlData.Append("<ids original=\"D2DDEA090700C0BD8CBA9B78965E5BA3\" modified=\"0CBA6B45F0812F429CDFF936D46EACE9\"/>");

                xmlData.Append("</xfdf>");

context.Response.Clear();

                context.Response.ContentType = "application/vnd.xfdf";

context.Response.Write(xmlData.ToString());

But instead of showing the PDF, it just displays the xfdf constructed above.

Please help.

Avatar

Former Community Member

I can't post the code on this site, because, XML doesn't display correctly.

Visit the following site and send me your email address:

http://www.nk-inc.com/support/sales/

I will reply with the XFDF file you can inspect.

Avatar

Former Community Member

you can also check out:

http://fdftoolkit.codeplex.com

FDFToolkit.net is open source, and uses iTextSharp technologies.

Avatar

Level 2

I have done this with iTextSharp already. But, I want to try without using any third party library.

Avatar

Level 2

My xfdf is like below,

<?xml version="1.0" encoding="UTF-8" ?>

<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">

<fields>

<field name="First_Name"><value>Jack</value></field>

<field name="Last_Name"><value>Shephered</value></field>

</fields>

<f href='http://localhost:53296/Documents/8a754934-c983-4a50-b00f-d291be59aeaf.pdf'/>

</xfdf>

context.Response.ContentType = "application/vnd.adobe.xfdf";

context.Response.Write(xmlData);

It now opens up an empty PDF file in the iFrame without populating the data from xfdf file.

Same XFDF file when imported manually from Acrobat, populates the data in the PDF file.